how to add grid to table with pander?

梦想与她 提交于 2019-12-05 16:37:27
scoa

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

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.

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

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!