当我尝试加载graphicx
或geometry
包时,我的Rmarkdown返回错误,错误如下:
---
output:
bookdown::pdf_document2:
keep_tex: true
header-includes:
- \usepackage[demo]{graphicx}
- \usepackage{hyperref}
- \usepackage{array}
- \usepackage{lastpage}
- \usepackage{lipsum}
- \usepackage{fancyhdr}
- \usepackage[hmargin=2cm,top=4cm,headheight=65pt,footskip=65pt]{geometry}
---
sometext
processing file: test.Rmd
output file: test.knit.md
! LaTeX Error: Option clash for package graphicx.
Error: LaTeX failed to compile test.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test.log for more info.
Execution halted
我正尝试将以下乳胶转换为rmarkdown,但没有成功:(
\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[demo]{graphicx}
\usepackage{hyperref}
\usepackage{array}
\usepackage{lastpage}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage[hmargin=2cm,top=4cm,headheight=65pt,footskip=65pt]{geometry}
\setlength{\parindent}{0.95cm}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[CE,CO,LE,LO,RE,RO]{} %% clear out all headers
\fancyhead[C]{%
\begin{tabular}{|m{3.0cm}|m{10.0cm}|m{2.5cm}|}
\hline
\includegraphics[height=1.5cm,width=2.5cm]{logo.png} &
\centering
\Huge{TITLE} &
\centering
\tiny{P\'ag. \thepage\ de \pageref{LastPage}\\
Data: 17/05/2013\\
Rev. 0}\tabularnewline
\hline
\end{tabular}%
}
\fancyfoot[CE,CO,LE,LO,RE,RO]{} %% clear out all footers
\fancyfoot[C]{%
\begin{tabular}{|m{3.0cm}|m{10.0cm}|m{2.5cm}|}
\hline
\includegraphics[height=1.5cm,width=2.5cm]{logo.png} &
\centering
\Huge{TITLE} &
\centering
\tiny{P\'ag. \thepage\ de \pageref{LastPage}\\
Data: 17/05/2013\\
Rev. 0}\tabularnewline
\hline
\end{tabular}%
}
\begin{document}
\chapter{Chapter title}
%% add this if you want the fancy style also on the first page of a chapter:
\thispagestyle{fancy}
\section{Section title}
\lipsum[1-10]
\end{document}
我在windows 10上,使用R 4.2.3
和Texlive完整的发行版已经安装,我能够编译.tex
的例子!
如果我直接在RMD中使用.tex
,我将得到如下错误:
---
output:
pdf_document:
keep_tex: true
header-includes:
- \usepackage{array}
- \usepackage{lastpage}
- \usepackage{lipsum}
- \usepackage{fancyhdr}
- \geometry{hmargin=2cm,top=4cm,headheight=65pt,footskip=65pt}
- \setlength{\parindent}{0.95cm}
- \pagestyle{fancy}
- \renewcommand{\headrulewidth}{0pt}
- \fancyhead[CE,CO,LE,LO,RE,RO]{} %% clear out all headers
- \fancyhead[C]{%
\begin{tabular}{|m{3.0cm}|m{10.0cm}|m{2.5cm}|}
\hline
\includegraphics[height=1.5cm,width=2.5cm]{logo.png} &
\centering
\Huge{TITLE} &
\centering
\tiny{P\'ag. \thepage\ de \pageref{LastPage}\\
Data: 17/05/2013\\
Rev. 0}\tabularnewline
\hline
\end{tabular}%
}
- \fancyfoot[CE,CO,LE,LO,RE,RO]{} %% clear out all footers
- \fancyfoot[C]{%
\begin{tabular}{|m{3.0cm}|m{10.0cm}|m{2.5cm}|}
\hline
\includegraphics[height=1.5cm,width=2.5cm]{logo.png} &
\centering
\Huge{TITLE} &
\centering
\tiny{P\'ag. \thepage\ de \pageref{LastPage}\\
Data: 17/05/2013\\
Rev. 0}\tabularnewline
\hline
\end{tabular}%
}
classoption: demo
---
\chapter{Chapter title}
%% add this if you want the fancy style also on the first page of a chapter:
\thispagestyle{fancy}
\section{Section title}
\lipsum[1-10]
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Scanner error: mapping values are not allowed in this context at line 23, column 17
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load -> <Anonymous>
Execution halted
1条答案
按热度按时间3vpjnl9f1#
问题是rmarkdown在插入你的头文件include之前就已经加载了一卡车的包,因此你不能再用你想要的选项加载它们了。
作为解决方法,您可以
hyperref
软件包,因为它已经加载\usepackage[...]{geometry}
替换为\geometry{...}
以修改已加载几何包的选项demo
选项设置为graphicx
比较麻烦。你真的需要它吗?它会阻止所有的图像显示。如果你真的需要它,你可以使用classoption: demo
强制所有的软件包。注意这会将该选项传递给所有加载的软件包。如果其他软件包也有该选项,结果可能会改变。bookdown::pdf_document2
默认使用article
类,这与你的book
类有很大的不同。完整文档: