无法使用自定义样式编织为pdf [英] Can't knit to pdf with custom styles

查看:100
本文介绍了无法使用自定义样式编织为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用自定义的mystyles.sty文件从RStudio编织为pdf.过去工作正常,但现在我已升级到RStudio 1.044,但出现错误.

Trying to knit to pdf from RStudio using a custom mystyles.sty file. This used to work fine but now that I have upgraded to RStudio 1.044 I get an error.

示例:

---
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的较旧版本一起使用,但仅此而已.如果我将include:...从YAML中剔除,它会毫无抱怨地呈现.有人能帮忙吗?

If I look at the tex file it produces I can't see any missing braces, and there isn't a line 1290. This is using the latest releases of RStudio, R and MacTex. AsI say, this used to work with an older version of RStudio but no more. If I take the includes:... bit out of the YAML it renders without complaint. Anyone able to help?

推荐答案

问题与 tex.SE .这是导致问题的模板的一部分:

The problem is linked to the rmarkdown latex template redefining \subparagraph{} in a way titlesec doesn't like, as hinted at by this answer on tex.SE. This is the part of the template that causes the problem:

$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前题中.这样编译就可以了:

Since the \subparagraph redefinition only happens if there is no subparagraph variable set, an easy workaround would be to set it in the yaml front matter. This compiles fine:

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

但这可能不是最佳解决方案:最好是从模板中修复该子项的定义.

This might not be the best solution however: it might be best to fix the subparagraph definition from the template.

这篇关于无法使用自定义样式编织为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆