I'm using Knitr to generate a PDF report where each page is structured using the multicol environment. The layout consists of two columns:
The first column contains a table.The second column contains a ggsurvminer-generated plot.
However, the issue I'm facing is that the plot starts higher than the table, causing misalignment between the two elements. Ideally, I want both to be aligned at the same level on the page.
MRE:
#```{r config, include=FALSE}newslide <- function(content) { code <- deparse(substitute(content)) cat(sep = "\n", knitr::knit_child( quiet = TRUE, text = c("```{r dpi=600, warning=FALSE, message=FALSE, echo=FALSE, results='asis', escape = TRUE}", code, "```") ) )}#```#```{r latex, echo=FALSE, results = 'asis', escape = "TRUE"}plot_list <- list()category <- c("A","B","C")for (cat in category){ fit <- survfit(Surv(time, status) ~ sex, data = lung) p <- ggsurvplot(fit, data = lung)plot_list[[cat]] <- p}for (cat in category){ plot1 <- plot_list[[cat]]$plot #I've also tried without "$plot" table1_latex <- kable(head(lung), format = "latex") newslide( content = { cat("\\begin{multicols}{2}\n") cat("\\noindent\n") print(table1_latex) cat("\\columnbreak\n") cat("\\begin{center}\n") print(plot1) cat("\n") cat("\\end{center}\n") cat("\\end{multicols}\n") })}
As you can see in the screenshot from my original code, the plot is even overlapping the header before it:Image may be NSFW.
Clik here to view.
Thank you for any suggestions!