r - 如何将 .sty 文件添加到 rmarkdown pdf_output

标签 r latex r-markdown tex

我不确定这里的方法是否正确,我整天都在寻找一种方法来执行此操作,但没有文档在其说明中足够明确。

我想使用如下所示的模板样式:

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}
}

最佳答案

虽然我不确定您尝试过哪种 yaml 结构,但 the page you might see 的答案是正确的。但是,该答案的缩进不正确。试试下面的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

关于r - 如何将 .sty 文件添加到 rmarkdown pdf_output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56174593/

相关文章:

R:返回质因数和指数

r - R中具有不同颜色的直方图样图

R 用 tidyr 扩展多列

r - 如何修复警告 "label `“多次定义”

r - 在 Sweave 中制作扁平化的 pdf

r - Stata 到 R 根据条件替换值

latex - 算法左边距和注释定制

r - 是否有用于模块化报告生成的\SweaveInput{} 的 R markdown 模拟?

parameters - 将参数从 R Markdown 传递到 Latex

替换 pandoc 表上的列名