You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rmarkdown插入LaTeX标题页后编织PDF正文不显示问题求助

问题原因

你自定义的title.tex文件错误加入了LaTeX文档的起止标签,而Rmarkdown编织PDF时会自动生成\begin{document}和\end{document}标签包裹所有正文内容:

  • 你在导入的title.tex中提前声明了\begin{document}并在标题页结束后写了\end{document},LaTeX解析到这个结束标签就会判定整个文档已经完结,Rmarkdown后续生成的正文内容完全不会被渲染。
  • 同时标题页属于正文范畴,不应该放在in_header对应的LaTeX导言区加载。
修复步骤
  1. 修改title.tex内容
    删除文件里的\begin{document}和末尾的\end{document},只保留如下内容:
\usepackage{graphicx}

\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}
  1. 调整Rmarkdown的YAML配置
    将导入title.tex的参数从in_header改为before_body,对应配置如下:
---
output:
  pdf_document:
    includes:
      before_body: title.tex
---

修改完成后重新编织文件,即可同时正常显示自定义标题页和Rmarkdown正文内容。

内容的提问来源于stack exchange,提问作者username97

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 18:48:01