First question on tex.stackexchange after lurking a while, apologies if my form is poor, comments to improve it are welcome.
I am converting a RMarkdown report to LaTeX using knitr
in RStudio with a preamble.tex file.
I have three levels of header using #, ##, ###
. #Header1 is the title of each study and must appear on a separate page, vertically centered (and possibly horizontally left aligned)
LaTeX commands \vspace, \bigskip and \newline as well as spaces (two spaces, \n, and html "br") are systematically ignored by knitr and #Header1 keeps appearing on top of the page. The most that happened was that a blank page was created before the title.
I failed to successfully adapt the code suggested in the remotely compatible questions I found. Attempts with packages titling
and sectsty
also failed because \maketitle
required between \begin{titlingpage}
and \end{titlingpage}
make the document title appear, not the #Header1 that must be included in the TOC.
Attempts with \begin{nscenter}
from this question gave the error "! You can't use `macro parameter character #' in vertical mode. l.206 #"
I was not able to understand this other question about \hfill
.
I have a hunch that something in my preamble overrides the commands, like this one asking to make a new page after each section :
\let\stdsection\section
\renewcommand\section{\newpage\stdsection}
but removing it simply puts the document title an the TOC on the first page. You must have understood by now that my abilities in LaTeX are limited.
I would be grateful for any tip that will help me make header1 vertically centered on a single page, either 1) individually with spaces or \begin{newcommand} + \end{newcommand} or 2) defining in the preamble that any Header1 defined by one # gets vertically centered.
Thanks a lot!
Best Answer
You can included LaTeX package directly in Rmd file and event function. Witch make the work easy and as my opinion better then sweave.
Here an example of a preampule for a .Rmd file I made.
And you can even add personnal command. with the usual with latex. You just have to add them right after the preampule.
Here a script for footnote I added in slide. It's in .css. The point is you can declare everything and usually the conversion is really straight forward and easy.
Finally, you can even declare direct LaTeX environment in your Rmd file.
I made a presentation about RMarkdown for my university, it's in French but the Gabarit file (template in French) contains a lot of code and maybe will help you understand more what I'm saying. (in the resources section at the bottom)