首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在标记中设置自定义章节编号

在标记中设置自定义章节编号
EN

Stack Overflow用户
提问于 2018-08-26 15:06:10
回答 1查看 1.1K关注 0票数 2

我正在创建一个R标记文档,它输出一个PDF文档。我的YAML标题如下:

代码语言:javascript
复制
---
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命令(只修改标题的显示方式):

代码语言:javascript
复制
\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文件时会出现一个错误:

代码语言:javascript
复制
! Argument of \paragraph has an extra }.
<inserted text> 
\par 
l.1290 \ttl@extract\paragraph
Error: Failed to compile Template.tex

我搞不懂它为什么跑不开。preamble.tex文件的内容如下:

代码语言:javascript
复制
% !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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-27 11:53:27

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

代码语言:javascript
复制
subparagraph: yes

你的YAML标题,c.f.several other answers.

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

代码语言:javascript
复制
documentclass: report

代码语言:javascript
复制
documentclass: book

到你的YAML头。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52027522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档