rstudio / rmarkdown-cookbook

R Markdown Cookbook. A range of tips and tricks to make better use of R Markdown.
https://bookdown.org/yihui/rmarkdown-cookbook/
581 stars 225 forks source link

How to do a two-column layout ? #19

Closed cderv closed 4 years ago

cderv commented 6 years ago

A specific question we find on SO, but that I can relate to because some colleagues often ask. More generally is how to customize the layout of your output. Maybe too broad or an idea for a specific chapter in the book.

Related SO questions:

cderv commented 5 years ago

This is a broader question than for presentation https://stackoverflow.com/questions/31753897/2-column-section-in-r-markdown

cderv commented 5 years ago

Related 📦 offering format with two column layout:

cderv commented 5 years ago

rticles 📦 has also two columns layout latex template I think.

cderv commented 5 years ago

https://stackoverflow.com/questions/34808612/how-make-2-column-layout-in-r-markdown-when-rendering-pdf Solution is to use some feature of pandoc variable for Latex: the classoptionvariables sets to twocolumn according to the documentclass set to article

Related to pandoc feature, and may be part of #106

cderv commented 5 years ago

Related : https://stackoverflow.com/questions/28000062/tables-and-figures-side-by-side-in-knitr-or-rmarkdown-beamer

cderv commented 5 years ago

https://stackoverflow.com/questions/19237190/2-column-report-in-r-markdown-render-html-aside-data-frame

cderv commented 4 years ago

This is now added in https://bookdown.org/yihui/rmarkdown-cookbook/multi-column.html with several recipes.

From all that was gathered above, I see two possible additions:

How to get full two columns document in PDF ?

From : https://github.com/yihui/rmarkdown-cookbook/issues/19#issuecomment-431581739, https://github.com/yihui/rmarkdown-cookbook/issues/19#issuecomment-428835793 and https://github.com/yihui/rmarkdown-cookbook/issues/19#issuecomment-431580529

Something like this seems to work using classoption: twocolumn and \onecolumn or \twocolumn command. But not easy to tune apparently

Examples ````r --- output: pdf_document: keep_tex: true classoption: twocolumn --- # Using two columns ```{r, echo = FALSE, results='asis'} cat(stringi::stri_rand_lipsum(10), sep = "\n") ``` \onecolumn # New chapter with only one column ```{r, echo = FALSE, results='asis'} cat(stringi::stri_rand_lipsum(5), sep = "\n") ``` ````

This could also be a way to mention packages with those kind of twocolumn format (pinp and rticles)

You know better than me about latex, so you may be able to see if it worths mentioning.

Using multicol latex package

From https://github.com/yihui/rmarkdown-cookbook/issues/19#issuecomment-426152647

It seems that multicol package is easier to use than the minipage in column.tex when using only with text. It does not work well with code chunk or figure without using another package (wrapfig).

See example ````r --- output: pdf_document header-includes: - \usepackage{multicol} --- # Using two columns \begin{multicols}{2} ```{r, echo = FALSE, results='asis'} cat(stringi::stri_rand_lipsum(2), sep = "\n") ``` \end{multicols} # New chapter with only one column ```{r, echo = FALSE, results='asis'} cat(stringi::stri_rand_lipsum(2), sep = "\n") ``` ```` giving ![image](https://user-images.githubusercontent.com/6791940/79506726-c92d4d00-8036-11ea-8b9e-dbdebd228797.png)

Again I am far from being a Tex expert, so I don't know specifically what this tex multicol 📦 is worth. I found about it in one of the SO answer and more in here. The current recipe could be just enough.

@yihui if you find one of the above useful addition, we can leave it open to not forget adding about these. Otherwise, we can close this issue.

cderv commented 4 years ago

classoption is now mentioned in cb82b3bfda9a7911e92d68a3d0cd3b085280a143 in the part about latex template

yihui commented 4 years ago

I just mentioned \onecolumn and \twocolumn in a footnote. I'll leave out the multicol package. Thanks!

overbeek42 commented 3 years ago

Just updating a now dead link to the page in the rmarkdown cookbook: https://bookdown.org/yihui/rmarkdown-cookbook/multi-column.html

yihui commented 3 years ago

@overbeek42 Thanks! I just updated the link above.

overbeek42 commented 3 years ago

Great. Sorry for responding to a closed issue. I later saw that this causes you anxiety. Didn't mean to.

On Fri, Dec 25, 2020, 4:24 PM Yihui Xie notifications@github.com wrote:

@overbeek42 https://github.com/overbeek42 Thanks! I just updated the link above.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yihui/rmarkdown-cookbook/issues/19#issuecomment-751262843, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKXSH6DQ766CSR3PHH7IE6DSWSVDFANCNFSM4FQKULQQ .

yihui commented 3 years ago

No worries! In this case, it didn't cause me any anxiety at all since it was extremely easy to deal with, and it's entirely reasonable to reply under this issue since you were pointing out a problem right inside this issue. I really appreciate that.

overbeek42 commented 3 years ago

Glad there's no hard feelings. Happy to be of some help after you enabled be to create amazingly crisp and neat slides to present my research!

On Fri, Dec 25, 2020, 5:33 PM Yihui Xie notifications@github.com wrote:

No worries! In this case, it didn't cause me any anxiety at all since it was extremely easy to deal with, and it's entirely reasonable to reply under this issue since you were pointing out a problem right inside this issue. I really appreciate that.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yihui/rmarkdown-cookbook/issues/19#issuecomment-751269425, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKXSH6AVDNFW6KXHVWYILPDSWS5GJANCNFSM4FQKULQQ .

piiskop commented 8 months ago
\begin{multicols}{2}

```{r, echo = FALSE, results='asis'}
cat(stringi::stri_rand_lipsum(2), sep = "\n")

\end{multicols}

New chapter with only one column

cat(stringi::stri_rand_lipsum(2), sep = "\n")

It does not work with verbatim code chunks though. And it is impossible to put subheadings inside multicols.