代码之家  ›  专栏  ›  技术社区  ›  mzkrc

! LaTeX错误:缺少\ begin{document}。错误:LaTeX无法编译paper_template.tex

  •  0
  • mzkrc  · 技术社区  · 11 月前

    我正在为下学期准备一份使用R Markdown和Latex的纸质模板。我边学习边经历,最近我面临的问题是错误信息 ! LaTeX Error: Missing \begin{document}. Error: LaTeX failed to compile paper_template.tex 当我编织我的Rmd文件时。这是R-Markdown文件的代码;

    ---
    title: "Paper Template"
    author: "AAA"
    abstract: ""
    output:
      pdf_document:
        latex_engine: xelatex
        includes:
          in_header: customized_paper_template.tex
    date: "2024-06-29"
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)```
    
    \newpage
    
    ## R Markdown
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    
    ## Including Plots
    
    You can also embed plots, for example: This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
    
    When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
    
    You can also embed plots, for example: This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
    
    When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
    
    ### Including Extra Plots
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    

    这里是自定义的_paper_template.tex文件的代码;

    \usepackage{fontspec}
    \usepackage{geometry}
    \geometry{a4paper, margin=1in}
    \usepackage{setspace}
    \renewcommand{\baselinestretch}{1.25}
    
    % Set body text font
    \setmainfont{Kepler Std Light Semicondensed}
    
    % Set title fonts
    \newfontfamily\titlefont{Tiempos Headline}
    
    % Set the font size for the document
    \AtBeginDocument{\fontsize{12pt}{14pt}\selectfont}
    
    % Define title formatting
    \usepackage{titlesec}
     \titleformat{\section}
      {\normalfont\LARGE\titlefont} % Title style
      {\thesection} % Section number
      {1em} % Space between number and title
      {} % No additional formatting before the title text
       [\titlerule[0.5pt]] % Add a line under the title with 0.5pt thickness
    
    \titleformat{\subsection}
      {\normalfont\Large\titlefont} % Title style
      {\thesubsection} % Section number
      {1em} % Space between number and title
      {} % No additional formatting before the title text
      [\titlerule[0.4pt]] % Add a line under the title with 0.4pt thickness
    
    \titleformat{\subsubsection}
      {\normalfont\normalsize\titlefont} % Title style
      {\thesubsubsection} % Section number
      {1em} % Space between number and title
      {} % No additional formatting before the title text
      [\titlerule[0.3pt]] % Add a line under the title with 0.3pt thickness
    
    \titleformat{\paragraph}
      {\normalfont\normalsize\titlefont} % Title style
      {\theparagraph} % Section number
      {1em} % Space between number and title
      {} % No additional formatting before the title text
      [\titlerule[0.2pt]] % Add a line under the title with 0.2pt thickness
    
    \titleformat{\subparagraph}
      {\normalfont\normalsize\titlefont} % Title style
      {\thesubparagraph} % Section number
      {1em} % Space between number and title
      {} % No additional formatting before the title text
      [\titlerule[0.2pt]] % Add a line under the title with 0.2pt thickness
    
    1 回复  |  直到 11 月前
        1
  •  0
  •   samcarter_is_at_topanswers.xyz    11 月前

    使用 [{\titlerule[0.2pt]}] 等来隐藏可选参数的方括号:

    % Define title formatting
    \usepackage{titlesec}
     \titleformat{\section}
      {\normalfont\LARGE\titlefont} % Title style
      {\thesection} % Section number
      {1em} % Space between number and title
      {} % No additional formatting before the title text
       [{\titlerule[0.5pt]}] % Add a line under the title with 0.5pt thickness