如何使用pander向表格添加网格? [英] how to add grid to table with pander?

查看:78
本文介绍了如何使用pander向表格添加网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R,knitr和pander,但找不到允许我在使用pander的桌子上打印网格的选项. 我试过了:

I am working with R, knitr and pander, and I can't find the option that would allow me to print a grid on a table with pander. I tried :

pander(tableToPrint, style='grid') 

但是它什么也没做,无论是使用此选项还是使用"multiline","rmarkdown"……我总是得到一条水平线,然后是列名,另一条水平线,所有数据和一条水平线.我想在每条线之间有一条水平线.另一种选择是替换行颜色.

but it doesn't do anything, neither with this option or with 'multiline', 'rmarkdown'... I always get an horizontal line, then the column names, another horizontal line, all my data and an horizontal line. I would like to have an horizontal line between every line. Another option would be to alternate row colors.

推荐答案

有一个旧答案给出了窍门可以在乳胶中做到这一点,但需要对Pandoc进行一些调整.需要将其添加到乳胶代码中:

There is an old answer that gives the trick to do that in latex, but in needs a bit of adaptation to pandoc. One needs to add this to the latex code:

\catcode`@=11
\let \savecr \@tabularcr
\def\@tabularcr{\savecr\hline}
\catcode`@=12

但是,如果您通过header-includes添加它,则不起作用,可能是因为它在模板中为时已晚.因此,解决方案是创建一个新模板pandoc -D latex > template.tex(或使用您常用的模板),并在\documentclass之后的顶部添加之前的代码.然后:

However, it doesn't work if you add it through header-includes, probably because it is too late in the template. So the solution is to create a new template pandoc -D latex > template.tex (or use your usual template) and to add the previous code at the top, just after \documentclass. Then:

---
title: "Untitled"
output:
  pdf_document:
    keep_tex: yes
    template: "template.tex"
---

在每一行产生一行.问题是,顶行和底行都翻了一番.

Produces lines at every row. The problem is, then, that the top and bottom line are doubled.

这对于docx输出是不可能的. Pandoc的docx模板只允许很少的自定义,而只能是段落样式.

This is impossible for a docx output. Pandoc's docx template allow very little customization, and only of paragraph style.

出于完整性考虑,html解决方案更加简单:

For the sake of completeness, the html solution is even easier:

---
title: "Untitled"
output: html_document
---
<style>
th, td {
    border-bottom: 2px solid black;
}
</style>

这篇关于如何使用pander向表格添加网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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