Cannot build pandoc with LaTeX \hline using RStudio RMarkdown - latex

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:
Use \hrulefill: Problem: Will only fill 90% of a single column. Putting it in every column doesn't fill the line
Use "---" to tell Pandoc I need a horizontal line: Problem: Ends the table
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

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.

Related

Pandoc Column Width for Twocolumn not working

I cannot get column width recognized. It is as if it is just ignored and each column is exactly 50% of the available space. Additionally the example implies I can tell it when I want the 2nd column to start but that is also ignored.
The following is from the Pandoc manual column example, but when I compile it via pandoc they are just each 50% width not what is specified. The frontmatter in my example was not provided in their example but its what I figure it must be to get the columns working. I've tried this with and without the frontmatter.
I'm using ubuntu 18.04 within WSL2 and pandoc version:
pandoc 2.17.1.1 Compiled with pandoc-types 1.22.1, texmath 0.12.4,
skylighting 0.12.2, citeproc 0.6.0.1, ipynb 0.2
I'm using these command line entry for compiling it: (I've also tried pdflatex engine as well)
pandoc mat_doc.md --pdf-engine=xelatex -o mat_doc.pdf
Here is the file:
---
output: pdf_document
classoption: twocolumn
---
:::::::::::::: {.columns}
::: {.column width="60%"}
contents
:::
::: {.column width="40%"}
contents
:::
::::::::::::::
How do I get different sized columns? Why does this not work per their manual? Thx!
The beamer columns you are trying to use, are something special in the beamer class and don't work with normal classes.
However under the hood, these columns are just glorified minipages - and these you can use in normal latex classes.
---
output: pdf_document
---
\noindent\begin{minipage}{.6\textwidth}
test
\end{minipage}
\begin{minipage}{.4\textwidth}
test
\end{minipage}

Latex - Nomenclature for a thesis when you have multiple chapters

I am writing my PhD thesis, and I have multiple chapters where I compile a list of tables, figures and references. However, I struggle to put my "List of Symbols", as I need to call them from multiple chapters. Their order is not very important at the moment, so a general list should be fine (i.e. I don't need to group symbols chapter by chapter).
When I use the following commands in one of the chapters (for example), nothing happens.
\nomenclature{$m$}{The mass (kg)}
\printnomenclature
If you have a template or know how to make this work, it would be highly appreciated.
My code structure is as the following:
\documentclass[a4paper,12pt,twoside]{report}
\usepackage[left=3cm,right=2.5cm,top=2cm,bottom=2.5cm]{geometry}
\usepackage{multirow}
\include{thesis.preamble} % where all packages are embedded.
\usepackage{nomencl}
\makenomenclature
\begin{document}
% -------------------------------------------
% [-] Title Page
% -------------------------------------------
\title{title of the study}
\normallinespacing
\maketitle
\preface
\input{prefaces/abstract}
\input{prefaces/acknowledgements}
% -------------------------------------------
% [-] Main Body
% -------------------------------------------
\body
% [-] Introduction
\input{body/chapter1}
% chapters in between.
% [-] Conclusion
\input{body/chapter8}
\end{document}

Any way to keep R Markdown from putting a LaTeX environment in a new paragraph?

Environments like align and gather are pretty clearly designed for use within a paragraph of LaTeX text, as two line breaks between the document text and the start of the math environment inserts an egregious two paragraph's worth of vertical white space. Markdown, though, always starts any LaTeX environment two lines below the text that's above it, even if you begin the environment on the very same line of the markdown code/text, and even if you put 2 spaces before it in order to add a single line break. Since there's no multiline math dislay native to markdown, this poses a dilemma.
Running \vspace{-\baselineskip} before the environment compensates well enough, but of course it would be better to just tell markdown not to insert the line breaks in the first place. Is that possible? And if not, then what would be the easiest way to automatically run \vspace{-\baselineskip} before the beginning of each align (and/or align*, gather, gather*, etc.) environment?
MWE:
---
output:
pdf_document:
keep_tex: 1
---
The following environment will get marked up with an extra two lines between it and
this text, putting it on a new paragraph and creating a lot of whitespace above it,
whether or not there's any line breaks in the markdown code:
\begin{gather*}
A \\ B
\end{gather*}
This can of course be hackily corrected by subtracting vertical space:
\vspace{-\baselineskip} \begin{gather*}
A \\ B
\end{gather*}
The best you can do in this situation is to automatically insert \vspace{-\baselineskip} at the start of every specific environment using the etoolbox package:
---
output:
pdf_document:
keep_tex: 1
header-includes:
- \usepackage{etoolbox}
- \AtBeginEnvironment{gather}{\vspace{-\baselineskip}}
- \AtBeginEnvironment{gather*}{\vspace{-\baselineskip}}
---
The following environment will get marked up with an extra two lines between it and
this text, putting it on a new paragraph and creating a lot of whitespace above it,
whether or not there's any line breaks in the markdown code:
\begin{gather*}
A \\ B
\end{gather*}
This can of course be hackily corrected by subtracting vertical space:
\begin{gather*}
A \\ B
\end{gather*}
This, however, is not optimal, as the gap inserted by the environment depends on the amount of text ending the preceding paragraph. As a result of Pandoc's processing, the amount is always the same (\abovedisplayskip), so it may be "better" to use
header-includes:
- \usepackage{etoolbox}
- \AtBeginEnvironment{gather}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}
- \AtBeginEnvironment{gather*}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}
You'll have to do this for all amsmath-related display alignments.

Pandoc-generated PDF: Change list numbering style

What is the way to change the style of numbers in ordered lists generated by Pandoc?
For the following Markdown input
1. One
2. Two
1. Sub 1
2. Sub 2
Pandoc generates the following Latex output
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\itemsep1pt\parskip0pt\parsep0pt
\item
One
\item
Two
\begin{enumerate}
\def\labelenumii{\arabic{enumii}.}
\itemsep1pt\parskip0pt\parsep0pt
\item
Sub 1
\item
Sub 2
\end{enumerate}
\end{enumerate}
This results in the following PDF output:
1. One
2. Two
1. Sub 1
2. Sub 2
While I'm trying to achieve
1. One
2. Two
2.1. Sub 1
2.2. Sub 2
I tried to redefine style of numbering in the default template with these commands
\renewcommand{\labelenumii}{\theenumii}
\renewcommand{\theenumii}{\theenumi.\arabic{enumii}.}
but as Pandoc generates explicit definition for labelenumii this solution does not work.
Update
It turns out that the problem could be resolved by using #. notation instead of 1. one. For whatever reason Pandoc skips styling only for lists defined this way and interprets the standard Markdown notation as an instruction to style list with plain numbers. Hopefully in future versions it will be a bit more flexible and will add the support for nested numbers in lists.
edit
This function of the latex writer that adds the \def\labelenumi{} part checks for numstyle == DefaultStyle && numdelim == DefaultDelim. As #oleg found out, this might be accomplished with #. list markers, so that this should work:
---
header-includes:
- \renewcommand{\labelenumii}{\theenumii}
- \renewcommand{\theenumii}{\theenumi.\arabic{enumii}.}
---
#. One
#. Two
#. Sub 1
#. Sub 2
There are two feature requests asking for a native markdown solution on the issue tracker (336 and 1627), as well as a discussion on the mailing list.
pre-edit answer
Of course, you could always compile to latex, postprocess the file to remove those \def\labelenumi{} lines, and then compile the latex file. Here is an example that works with the standard latex template.
test.md
---
header-includes:
- \renewcommand{\labelenumii}{\theenumii}
- \renewcommand{\theenumii}{\theenumi.\arabic{enumii}.}
---
1. One
2. Two
1. Sub 1
2. Sub 2
commands:
pandoc test.md -t latex -s | sed '/\\def\\labelenumi/d' > test.tex
xelatex test.tex
But all the lists of your document will be affected, and you need to write the latex compilation commands yourself.

Custom appendix in Latex

I'm Trying to solve a little problem that I have with a book I'm writing, I was wondering if could you give me a hand with my work.
I'm trying to rename the automatic captions in the appendix's tables
that I have. By default Latex do this:
Appendix A:
Table A.1
Table A.2
.
.
Appendix B:
Table B.1
Table B.2
.
.
The problem is: I have 6 chapters in my book, but each chapter except
the first one have appendices and All appendix go in the end of the
book. And All tables and figures in the appendix are A not B or C,
like this:
Anexo 2 <- The renamed appendix 2
Table A2_1
Table A2_2
Table A2_3
.
.
Anexo 3
Table A3_1
Table A3_2
Table A3_3
.
.
Could you help me??? I'll appreciate it so much
Thanks,
Dennis
Firstly, to change 'appendix' to 'Anexo',
\renewcommand{\appendixname}{Anexo}
The \appendix command changes the way sectional units are numbered. I too have found the \appendix command sometimes causes problems since everything which follows it is treated as part of the appendix.
You can create a section labelled 'Appendix' with distinctive numbering by using the \section command with suitably redefined commands for the counters. The following example generates a single 'Appendix' with equations numbered A-1, A-2, ...
\renewcommand{\theequation}{A-\arabic{equation}}
% redefine the command that creates the equation no.
\setcounter{equation}{0} % reset counter
\section*{APPENDIX} % use *-form to suppress numbering
With several appendices you can get appropriate numbering by redefining the \thesection command and resetting the section counter.
Look into the appendix package and its appendices environment. For localized names, look into the babel package instead.

Resources