问题
This is a great answer on how to do a 2-column layout in R-Markdown when rendering PDF.
Basically the answer is 'add the following to the header':
---
output:
pdf_document:
classoption: twocolumn
---
But how do I make it three columns or more?
回答1:
To generate a html file with multiple columns, you could use the CSS grid layout:
---
output: html_document
---
:::: {style="display: grid; grid-template-columns: 20% 50% 20%; grid-column-gap: 5%; "}
::: {}
contents...
:::
::: {}
contents...
:::
::: {}
contents...
:::
::::
If you want to use four (or more) columns:
:::: {style="display: grid; grid-template-columns: pc1% pc2% pc3% pc4%; grid-column-gap: pgap%; "}
Adjust the column size and gap percentages to your needs.
This won't work if you replace html_doument with pdf_document. If you are particularly interested in generating a pdf output, a workaround would be to open the html file with a browser and then printing it to a pdf file.
来源:https://stackoverflow.com/questions/61724367/how-to-make-multi-column-layout-in-r-markdown-when-rendering-pdf