Can't knit to pdf with custom styles

时光总嘲笑我的痴心妄想 提交于 2019-12-04 09:50:00
scoa

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$

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.

Please see this link . See twsh's answer. It worked for me. The following is his answer.

I think that another option is to set the 'subparagraph' variable to true (--variable=subparagraph on the command line). Then titlesec.sty works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!