我正在制作一个表格,它很宽只是因为表格标题很长。我想使用两行(或更多行)来编写表格标题,以便最终 PDF 文档中的表格保持清晰。
最佳答案
我假设您实际上指的是 rmarkdown
而不是 knitr
,因为您没有提到使用 kable
。因此,您可以更好地控制表格的格式。
rmarkdown
直接使用 pandoc,因此检查 there 会提供丰富的信息。为了洞察力。具体来说,作者讨论tables in markdown的地方.
我只测试了两种格式,它们都支持多行标题:multiline_tables
(命名方便)和grid_tables
,这两种格式都支持 OOB knitr
。我将两者渲染为 HTML 和 PDF (LaTeX),并且没有出现任何错误。我从网站复制了示例,并在标题中添加了反斜杠以强制多行。
multiline_table
格式:
-------------------------------------------------------------
Centered Default Right Left\
Header Aligned Aligned Aligned
----------- ------- --------------- -------------------------
First row 12.0 Example of a row that
spans multiple lines.
Second row 5.0 Here's another one. Note
the blank line between
rows.
-------------------------------------------------------------
Table: Here's the caption. It, too, may span
multiple lines.
以及 grid_table
格式:
+---------------+---------------+--------------------+
| Fruit | Price | Advantages\ |
| | | or\ |
| | | whatever |
+===============+===============+====================+
| Bananas | $1.34 | - built-in wrapper |
| | | - bright color |
+---------------+---------------+--------------------+
| Oranges | $2.10 | - cures scurvy |
| | | - tasty |
+---------------+---------------+--------------------+
Table: Another table. This is the grid_table format.
它们渲染到:
关于r - 如何将 R Markdown 文档中的表头分成多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30337802/