将 Latex 转换为 RMD

问题描述 投票:0回答:1

当我尝试加载

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
示例!

r latex r-markdown markdown
1个回答
1
投票

问题是 rmarkdown 甚至在插入您的标头包含之前就已经加载了大量的包裹。因此,您不再能够使用您想要的选项加载它们。

作为解决方法,您可以

  • 只需删除

    hyperref
    包,因为它已经加载

  • \usepackage[...]{geometry}
    替换为
    \geometry{...}
    来修改已经加载的几何包的选项

  • demo
    选项设置为
    graphicx
    更棘手。你真的需要它吗?它会阻止您显示所有图像。如果你真的需要它,你可以用
    classoption: demo
    强制进入所有包。请注意,这会将选项传递给所有加载的包。如果其他包也有这个选项,结果可能会改变。

  • 如果你真的想复制你的乳胶文档,你可能还想更改文档类,因为

    bookdown::pdf_document2
    默认使用
    article
    类,这与你的
    book
    类非常不同。


---
output:
  bookdown::pdf_document2: 
    keep_tex: true
header-includes:
  - \usepackage{array}
  - \usepackage{lastpage}
  - \usepackage{lipsum}
  - \usepackage{fancyhdr}
  - \geometry{hmargin=2cm,top=4cm,headheight=65pt,footskip=65pt}
classoption: demo
---

sometext
© www.soinside.com 2019 - 2024. All rights reserved.