2

Note: This summary can be maxed with other summary calls where a line every row is needed, so a solution that puts lines between every row of every table will not work. Need it just for the tables I'm creating.

Using latest RStudio, I have an object type for which summary.type produces Pandoc output of a table. I would like to, in pdf / LaTeX output, have a horizontal line between each row of the table. All my attempts fail with the error :

! Misplaced \noalign.
\hline ->\noalign 
                  {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.207 \hline

pandoc: Error producing PDF from TeX source

Given the following in a .md file:

------------------------------------------------------------------------------------------------
               term        estimate    std.error   statistic   p.value     N           adj.rsq   
------------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
**1**         NA          26.8        0.766       35          0           1466        0.004      

**2**         NA          0.012       0.012       0.939       0.348       .           .          

-------------------------------------------------------------------------------------------------

Another option is to add labels after you have created the table

\hline

And executing the following command (created by RStudio):

/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS type.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output type.pdf --table-of-contents --toc-depth 3 --template ~/Library/R/3.2/library/rmarkdown/rmd/latex/default-1.14.tex --highlight-style tango --latex-engine /Library/TeX/texbin/pdflatex --variable graphics=yes --variable 'geometry:margin=1in'

Remove that last line (the "\hline") and everything compiles correctly.

When I create html instead of pdf, the \hline is ignored (as it should be) and the file is created successfully.

What am I doing wrong? What is the minimum LaTeX I can embed in my Pandoc output in order to have a line with each row of a table?

Attempted solutions:

  1. Use \hrulefill: Problem: Will only fill 90% of a single column. Putting it in every column doesn't fill the line
  2. Use "---" to tell Pandoc I need a horizontal line: Problem: Ends the table
  3. Change LaTeX template so every row of every table has a line separating it: Problem: Only want to does this for the rows created by summary.myType, not for all tables anywhere in the document

Attempted solutions and results:

------------------------------------------------------------------------------------------------
               term        estimate    std.error   statistic   p.value     N           adj.rsq   
------------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
**1**         NA          26.8        0.766       35          0           1466        0.004      

\hrulefill    \hrulefill  \hrulefill  \hrulefill  \hrulefill  \hrulefill  \hrulefill  \hrulefill  

**2**         NA          0.012       0.012       0.939       0.348       .           .          

---

**3**         NA          -0.718      0.291       -2.469      0.014       .           .          

-------------------------------------------------------------------------------------------------

Another option is to add labels after you have created the table

What happened w/ 1st 2 solutions

Greg Dougherty
  • 3,281
  • 8
  • 35
  • 58
  • Possible duplicate of [how to add grid to table with pander?](http://stackoverflow.com/questions/34853128/how-to-add-grid-to-table-with-pander) – scoa Feb 12 '16 at 10:21
  • 1
    `\hline` can only be used inside a `tabular` or similar environment. To draw an horizontal line elsewhere in a latex document, use `\hrulefill`. To add hlines every row, see the dupe – scoa Feb 12 '16 at 10:22
  • In Pandoc's Markdown you can simply create a horizontal line like this: `---`, see http://pandoc.org/README.html#horizontal-rules – mb21 Feb 12 '16 at 11:01
  • @mb21 Attempting to create a horizontal line with "---" terminates the table – Greg Dougherty Feb 12 '16 at 16:04
  • @scoa Unfortunately, adding a line to every row of every table in the document, as opposed to the rows of the table I'm producing, is outside teh scope of what I can do. – Greg Dougherty Feb 12 '16 at 16:06
  • @scoa In a table, \hrulefill only makes a line that fills ~90% of the column it's in. So even if I put it in every column, it provides some separation, but not a solid line – Greg Dougherty Feb 12 '16 at 16:08

1 Answers1

0

The answer is there's no answer. This is a snip of the tex that Pandoc's markdown -> tex converter is creating:

\begin{longtable}[c]{@{}llll@{}}
\toprule
\begin{minipage}[b]{0.16\columnwidth}\raggedright\strut
\strut\end{minipage} &

Every single cell is its own "page", with its own margins, as such nothing that produces a line can extend beyond that page, and through those margins.

Short of creating a template that forces LaTeX to put a line at the end of each row of every single table in the file (as was suggested here), I do not believe there's any way to do what I want, short of coding up the LaTeX for the table myself.

Community
  • 1
  • 1
Greg Dougherty
  • 3,281
  • 8
  • 35
  • 58