header - 在 Markdown 中设置自定义章节编号

标签 header r-markdown customization

我正在创建一个输出 PDF 文档的 R Markdown 文档。我的 YAML header 如下:

---
title: "Introduction"
author: "John Doe
date: "August 26, 2018"
mainfont: Pancetta Pro
documentclass: book
output:
  pdf_document:
    number_sections: true
    df_print: kable
    fig_caption: yes
    fig_width: 6
    highlight: tango
    includes:
      in_header: preamble.tex
    latex_engine: xelatex
geometry: headheight=25pt, tmargin=25mm, bmargin=20mm, innermargin=20mm, outermargin=20mm
---

preamble.tex 文件中,我想要以下 LaTeX 命令(仅修改标题的显示方式):

\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}    
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Huge}{\bfseries\thechapter}{0.2pt}{\thicklines\thehook}[\vspace{0.5em}]

但是,当 preamble.tex 中包含最后几行时,我在编写 R Markdown 文件时收到错误:

! Argument of \paragraph has an extra }.
<inserted text> 
\par 
l.1290 \ttl@extract\paragraph
Error: Failed to compile Template.tex

我不明白为什么它不能运行。 preamble.tex文件的内容如下:

% !TeX program = lualatex
\usepackage{relsize} % To make math slightly larger.

\newcommand{\thehook}{%
 \hspace{.5em}%
 \setlength{\unitlength}{1em}%
 \raisebox{-.5em}{\begin{picture}(.4,1.7)
  \put(0,0){\line(1,0){.2}}
  \put(.2,0){\line(0,1){1.7}}
  \put(.2,1.7){\line(1,0){.2}}
 \end{picture}}%
 \hspace{0.5em}%
} %This creates the "hook" symbol at the beginning of each chapter.

\usepackage{anyfontsize}
\usepackage{fontspec}
\setmainfont{Pancetta Pro}

%   We set the font for the chapters:
\newfontfamily\chapterfont{Pancetta Pro}

%   And now for the sections:
\newfontfamily\sectionfont{Pancetta Pro}


\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[RO]{\large\sffamily\rightmark\thehook\textbf{\thepage}}
\fancyhead[LE]{\large\sffamily\textbf{\thepage}\thehook\rightmark}

\fancypagestyle{plain}{%
 \fancyhf{}
}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}

\fontsize{12}{20}\selectfont

\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Huge}{\bfseries\thechapter}{0.2pt}{\thicklines\thehook}[\vspace{0.5em}]

排除前面代码中的最后 6 行时,不会出现错误,并且会创建 pdf。

最佳答案

如果您想将 titlesecrmarkdown 一起使用,则必须添加

subparagraph: yes

到您的 YAML header ,参见several other answers .


rmarkdown 使用的默认 LaTeX 类是 article,它没有章节。您应该添加

documentclass: report

documentclass: book

到您的 YAML header 。

关于header - 在 Markdown 中设置自定义章节编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52027522/

相关文章:

Python:检查 header 格式

Rmarkdown & PDF 输出 : Evaluate Markdown inside Latex section

yaml - R Markdown (Pandoc) 带有短标题的投影仪演示文稿

jenkins - 如何自定义 Jenkins 主题?

JQuery:如何在一条语句中以字符串形式获取选择器的所有 html 属性?

PHP header() 不起作用

c# - WPF DataGrid header 文件大小排序

r - RMarkdown 演示文稿中的列中的代码

c++ - 自定义 VS C++ 调试器

macos - Emacs/OSX 默认字体设置不存在