2 column Section in R Markdown

后端 未结 5 1921
情书的邮戳
情书的邮戳 2020-11-28 01:51

I\'m very new at R Markdown and I\'m putting together an R Markdown HTML page for some new R users at my work to give them an intro and walk them through some simple demos.

5条回答
  •  温柔的废话
    2020-11-28 02:19

    Update (May 2020)

    Pandoc now supports a fenced_div approach for specifying environments. This is also the approach that the R Markdown Cookbook recommends for multi-column environments, with some special tweaks to the preamble files.

    I've updated my original linked example (below) to reflect this best practice... but I've also packaged an R Markdown template that bundles together the necessary preamble files. A MWE with this fenced div approach might look like this:

    ---
    title: "Two column test"
    output:
      html_document:
        css: preamble.css
      pdf_document:
        includes:
          in_header: preamble.tex
    ---
    
    This is regular text spanning the whole page. But here comes a two-column section.
    
    :::::: {.columns}
    ::: {.column width="48%" data-latex="{0.48\textwidth}"}
    This text is in the left column.
    :::
    ::: {.column width="4%" data-latex="{0.04\textwidth}"}
    \ 
    
    :::
    :::::: {.column width="48%" data-latex="{0.48\textwidth}"}
    This text is in the right column.
    :::
    ::::::
    \newline
    
    And back to a regular single-column environment.
    

    Original answer

    A late contribution to this thread, but just to point out that you can combine @rawr and @Alison's answers to enable multicolumn sections for both HTML and PDF. R Markdown/knitr is smart enough to parse only the relevant commands depending on the desired output format. I'm often knitting the same document to multiple formats, so this is very convenient. Here is a fully developed example.

提交回复
热议问题