如何将 .sty 文件添加到 rmarkdown 的 pdf_output 中。

3

我不确定我的方法是否正确,我已经整天搜索了一种实现此操作的方法,但是没有一份文档能够清晰地指导。

我想使用以下模板样式:

enter image description here

我已经有了 .sty 文件。我尝试在 rmarkdown 中连接该文件,并编写以下标题:


---
title: "title"
author: "author"
date: "`r format(Sys.time(), '%d %B, %Y')`"
mainfont: Arial
output:
    pdf_document:
      latex_engine: xelatex
      includes:
        template: analysis_orax.sty

---

然而,这并没有添加样式。如果我添加 .tex 文件,它会添加所有正文文字,这不是我想要的。
我不太喜欢使用 .tex 或 .sty;我只想要一个漂亮格式的 .pdf 报告!!
.sty 文件:
\usepackage{titlesec} 
\usepackage{tikz}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage[left=4cm,right=2.5cm,top=2.5cm,bottom=2cm]{geometry}
\usepackage{fancyhdr}

%------------------Main Font-------------------------
\setmainfont{Fira Sans}
%Make sure you have the compiler "XeLaTeX" activated on your settings for your LaTeX document in order to see the font 

%------------------Color Set--------------------------
\definecolor{LightBlue}{RGB}{66, 163, 251}
\definecolor{DarkBlue}{RGB}{36, 100, 176}
\definecolor{LightGray}{gray}{.94}
\definecolor{DarkGray}{gray}{.172}
\definecolor{Orange}{RGB}{229, 133, 3}
\definecolor{MediumBlue}{RGB}{38, 119, 193}

%------------------Section Default Setting-------------
\titleformat*{\section}{\color{DarkBlue}\normalfont\bfseries\Huge}
\titleformat*{\subsection}{\color{LightBlue}\normalfont\bfseries\LARGE}
\titleformat*{\subsubsection}{\color{MediumBlue}\normalfont\bfseries\LARGE}

%-------------------Section Numbers Removal------------
\setcounter{secnumdepth}{0}


%-------------------------Header & Footer------------------------

\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{
\begin{tikzpicture}[remember picture,overlay] \node[anchor=north west, yshift=1.5mm, xshift=-1.5mm] at (current page.north west) {\includegraphics[height=25mm]{figures/header_corner.png}};
\end{tikzpicture}
}
\fancyfoot[C]{
\begin{tikzpicture}[remember picture,overlay] \node[anchor=south east, yshift=-1.5mm, xshift=1.5mm] at (current page.south east) {\includegraphics[height=29mm]{figures/banner.png}};
\end{tikzpicture}
\textcolor{LightGray}{\thepage}
}


2
你需要使用 header-includes;请参考例如 https://tex.stackexchange.com/questions/171711/how-to-include-latex-package-in-r-markdown。 - duckmayr
我尝试了这个建议,但没有正确的yaml结构:https://tex.stackexchange.com/questions/171711/how-to-include-latex-package-in-r-markdown - Corey Pembleton
1个回答

6

虽然我不确定你尝试的是哪种yaml结构,你可能看到的页面有正确的答案。然而,该答案的缩进是不正确的。请尝试下面的yaml,其中我们需要用两个空格进行缩进以指定output的参数。

---
title: "title"
author: "author"
date: "`r format(Sys.time(), '%d %B, %Y')`"
mainfont: Arial
output:
  pdf_document:
    latex_engine: xelatex
    includes:
      in_header:
        - analysis_orax.sty
---

该部分内容:

这个章节

in_header:
  - analysis_orax.sty

等同于

in_header: analysis_orax.sty

在你的情况下,如果你有更多的文件(例如.sty或者.tex)需要包含在页眉中,你可以使用-和换行符来表示文件名,如下所示:

in_header:
  - analysis_orax.sty
  - another_one.sty

1
谢谢@carlos-luis-rivera,这解决了我的问题,我的间距有误!干杯! - Corey Pembleton

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接