latexr-markdownpage-title

Body text after latex title page not showing, Rmarkdown


I have successfully been able to add a latex title page to my Rmarkdown file, but the rest of the document doesn't appear. Here is my YAML:

---

output:
  pdf_document:
    includes:
      in_header: title.tex
---

I haven't changed anything else in the Rmarkdown file, it has the standard text starting with: This is an Rmarkdown document etc. I include my title.tex file:


\usepackage{graphicx}
\begin{document}

\begin{titlepage}
    \begin{center}
    
    \includegraphics{UCTLogoLong.jpg} 
        \vspace*{2cm}
        
        \textbf {\Huge Applied Spatial Data Analysis} % MAIN TITLE
        \vspace{0.5cm}
        
        {\LARGE Assignment 1} % SUBTITLE
        \vspace{1cm}
        
        \noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}} 
        
        {\LARGE Geostatistics}
        \noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}} 
        \vspace{1cm}
        
        {\Large NAME }  % AUTHOR
        
        {\Large STUDENT NUMBER}
        \vspace{1cm}
        
        \includegraphics[width=5cm,height=5cm,keepaspectratio]{statslogo.png} 
         
    \vspace{0.2cm}
        
        Department of Statistical Sciences\\
        University of Cape Town\\
        South Africa\\
        \today
        
    \end{center}
\end{titlepage}

\end{document}

I am relatively new to Rmarkdown and have no idea why the standard Rmarkdown text isn't showing in knitted pdf. Any help will be much appreciated.


Solution

  • The problem is that with the \begin{document}...\end{document} you tell latex that it should ignore everything after that. Instead you could issue the content of the title page \AtBeginDocument{...}

    title.tex:

    \usepackage{graphicx}
    \AtBeginDocument{
    
    \begin{titlepage}
        \begin{center}
        
        \includegraphics{example-image-duck} 
            \vspace*{2cm}
            
            \textbf {\Huge Applied Spatial Data Analysis} % MAIN TITLE
            \vspace{0.5cm}
            
            {\LARGE Assignment 1} % SUBTITLE
            \vspace{1cm}
            
            \noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}} 
            
            {\LARGE Geostatistics}
            \noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}} 
            \vspace{1cm}
            
            {\Large John Doe }  % AUTHOR
            
            {\Large something}
            \vspace{1cm}
            
            \includegraphics[width=5cm,height=5cm,keepaspectratio]{example-image-duck} 
             
        \vspace{0.2cm}
            
            Department of Statistical Sciences\\
            University of Cape Town\\
            South Africa\\
            \today
            
        \end{center}
    \end{titlepage}
    \clearpage
    }
    

    Furthermore, I had to remove the empty line in

    ---
    output:
      pdf_document:
        includes:
          in_header: title.tex
    ---
    

    enter image description here