4

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') 

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.

scoa
  • 19,359
  • 5
  • 65
  • 80
Malta
  • 1,883
  • 3
  • 17
  • 30
  • 2
    `pander` passes options to the markdown file only, but it is then transformed by pandoc to html, latex/pdf, etc. If you want to have horizontal lines in your output, you have to tweak the template, but the solution then depends a lot on what your output format is. So, what is it? – scoa Jan 18 '16 at 16:26
  • I am not sure, I am currently balancing between pdf and docx. If you have a solution for any of this output, it will make my choice ! – Malta Jan 18 '16 at 18:15

1 Answers1

6

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>
Community
  • 1
  • 1
scoa
  • 19,359
  • 5
  • 65
  • 80
  • Ok I'm gonna switch to html then :). The line you indicate "color" lines, but in basic html output, I already get lines. – Malta Jan 19 '16 at 03:57