Search code examples
pdfr-markdownpngpandocquarto

Put 2 chunks of code side by side in RMarkdown or Quarto


How can I put 2 chunks of code side by side in the output file of RMarkdown or Quarto ?

Code

library(dplyr)
mtcars %>% select(gear)
library(dplyr)
select(mtcars, gear)

Desired layout in the PDF or HTML file enter image description here


Solution

  • ---
    title: "Untitled"
    output: html_document
    ---
    
    :::::::::::::: {.columns}
    ::: {.column width="50%"}
    
    
    ```{r warning=FALSE,message=FALSE}
    library(dplyr)
    mtcars %>% select(gear)
    ```
    
    :::
    ::: {.column width="50%"}
    
    ```{r warning=FALSE,message=FALSE}
    library(dplyr)
    select(mtcars, gear)
    ```
    
    :::
    ::::::::::::::
    

    enter image description here

    used This SO question as a resource. This is using pandoc to format the document in Rmarkdown HTML output