带标题的R降价表 [英] R markdown table with a caption

查看:74
本文介绍了带标题的R降价表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用正常的markdown表示法在代码块之外创建表,并向其添加标题.这是一个示例文件(摘自此处:

I'm trying to create a table outside of a code chunk using normal markdown notation and to add a caption to it. Here's an example file (taken from here:

---
output: pdf_document
---

| First Header  | Second Header | Third Header         |
| :------------ | :-----------: | -------------------: |
| First row     | Data          | Very long data entry |
| Second row    | **Cell**      | *Cell*               |
| Third row     | Cell that spans across two columns  ||
[Table caption, works as a reference][section-mmd-tables-table1]

不幸的是,这产生了一个相当可悲的字符串:

This unfortunately produces a rather sad string:

删除方括号中的标题行会使表格很好(但显然没有标题):

Removing the caption line in square brackets produces the table fine (but without the caption, obviously):

如果我将数据制作成实际的data.frame并使用kable(如此处此处但我希望避免这样做.

This can be achieved if I made my data into an actual data.frame and used kable as shown here but I'm looking to avoid having to do this.

推荐答案

链接指南引用了 MultiMarkdown ,而RMarkdown使用了 Pandocs .字幕在Pandoc中的工作方式略有不同.以下应该可以解决问题.语法为Table:,后跟您的标题; Pandocs自动编号.在表格末尾和标题行之间保留一行空白.

The linked guide refers to MultiMarkdown, while RMarkdown uses Pandocs. Captions work a little bit differently in Pandoc. The following should do the trick. The syntax is Table: followed by your caption; Pandocs numbers automatically. Leave one line blank between the end of the table and the caption line.

---
output: pdf_document
---

| First Header  | Second Header | Third Header         |
| :------------ | :-----------: | -------------------: |
| First row     | Data          | Very long data entry |
| Second row    | **Cell**      | *Cell*               |
| Third row     | Cell that spans across two columns  ||

Table: Your Caption

这篇关于带标题的R降价表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆