gpt4 book ai didi

latex - 无法使用自定义样式编织为 pdf

转载 作者:行者123 更新时间:2023-12-04 22:57:04 25 4
gpt4 key购买 nike

尝试使用自定义 mystyles.sty 文件从 RStudio 编织为 pdf。这曾经工作正常,但现在我已经升级到 RStudio 1.044 我收到一个错误。

例子:

---
title: "Test"
output:
pdf_document:
includes:
in_header: mystyles.sty
---



## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

使用此样式文件:
\usepackage{titlesec}

\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
\definecolor{coolblack}{rgb}{0.0, 0.18, 0.39}

\titleformat{\title}
{\color{airforceblue}\normalfont\Large\bfseries}
{\color{airforceblue}\thesection}{1em}{}
\titleformat{\section}
{\color{coolblack}\normalfont\Large\bfseries}
{\color{coolblack}\thesection}{1em}{}

给我这个错误:
output file: test.knit.md

! Argument of \paragraph has an extra }.
<inserted text>
\par
l.1290 \ttl@extract\paragraph

pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted

如果我查看它生成的 tex 文件,我看不到任何缺少的大括号,并且没有 1290 行。这是使用 RStudio、R 和 MacTex 的最新版本。正如我所说,这曾经适用于旧版本的 RStudio,但不再适用。如果我将包含:...从 YAML 中提取出来,它会毫无怨言地呈现出来。任何人都可以提供帮助?

最佳答案

问题与rmarkdown latex template有关重新定义 \subparagraph{}在某种程度上titlesec不喜欢,正如 tex.SE 上的这个答案所暗示的那样.这是导致问题的模板部分:

$if(subparagraph)$
$else$
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
$endif$

\subparagraph重新定义仅在没有设置子段落变量时发生,一个简单的解决方法是在 yaml 前端设置它。这编译得很好:
---
title: "Test"
output:
pdf_document:
includes:
in_header: mystyles.sty
subparagraph: true
---

然而,这可能不是最好的解决方案:最好从模板中修复分段定义。

关于latex - 无法使用自定义样式编织为 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40439701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com