简体   繁体   中英

How to add .sty file to rmarkdown pdf_output

I'm not sure if I have the right approach here, I've been searching all day for a way to do this, none of the documents are explicit enough in their instruction.

I would like to use a template style which looks like this:

在此处输入图片说明

Which I have the .sty file for. I've tried to connect that file in my rmarkdown, with a header like this:


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

---

However, this isn't adding the style. If I add the .tex file, it adds all of the body text, which isn't what I'm going for.

I don't quite care for using .tex or .sty; all I want is to have a nicely formatted .pdf for reporting!!

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

Though I am not sure which yaml structure you have tried, the page you might see has the right answer. However, the indentation of that answer was not correct. Just try the yaml below, in which we need to indent by two spaces to specify the arguments of 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
---

The section

in_header:
  - analysis_orax.sty

is equivalent to

in_header: analysis_orax.sty

in your case, but if you have more files ( .sty or .tex etc.) to include in header, you can use - and line breaks to indicate the file names, as shown below.

in_header:
  - analysis_orax.sty
  - another_one.sty

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM