使用 Rmarkdown 创建tufte_bookpdf,页码以某种方式导致作者显示在目录中的页面顶部,如下所示:
我想删除它,或者用书名代替它。目录中的编号本身也很分散注意力,所以我想把它也删除,同时保留序言和正文中的编号。
我尝试在 TeX 文件中找到导致此问题的原因,但找不到。
以下是 Rmarkdown 中的一个最小工作示例:
---
title: ".Rmd tufte_book page numbering"
author: "Author"
documentclass: tufte
output:
tufte::tufte_book:
toc: true
number_sections: true
---
\frontmatter
# Preface
\mainmatter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
生成的 TeX 文件如下:
\documentclass[]{tufte-book}
% ams
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\else % if luatex or xelatex
\makeatletter
\@ifpackageloaded{fontspec}{}{\usepackage{fontspec}}
\makeatother
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\makeatletter
\@ifpackageloaded{soul}{
\renewcommand\allcapsspacing[1]{{\addfontfeature{LetterSpace=15}#1}}
\renewcommand\smallcapsspacing[1]{{\addfontfeature{LetterSpace=10}#1}}
}{}
\makeatother
\fi
% graphix
\usepackage{graphicx}
\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}
% booktabs
\usepackage{booktabs}
% url
\usepackage{url}
% hyperref
\usepackage{hyperref}
% units.
\usepackage{units}
\setcounter{secnumdepth}{2}
% citations
% pandoc syntax highlighting
% longtable
% multiplecol
\usepackage{multicol}
% strikeout
\usepackage[normalem]{ulem}
% morefloats
\usepackage{morefloats}
% tightlist macro required by pandoc >= 1.14
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
% title / author / date
\title{.Rmd tufte\_book page numbering}
\author{Author}
\begin{document}
\maketitle
{
\setcounter{tocdepth}{1}
\tableofcontents
}
\frontmatter
\chapter{Preface}\label{preface}
(\ldots{})
\mainmatter
\chapter{Chapter}\label{chapter}
(\ldots{})
\chapter{Chapter}\label{chapter-1}
(\ldots{})
\chapter{Chapter}\label{chapter-2}
(\ldots{})
\chapter{Chapter}\label{chapter-3}
(\ldots{})
\chapter{Chapter}\label{chapter-4}
(\ldots{})
\chapter{Chapter}\label{chapter-5}
(\ldots{})
\chapter{Chapter}\label{chapter-6}
(\ldots{})
\chapter{Chapter}\label{chapter-7}
(\ldots{})
\chapter{Chapter}\label{chapter-8}
(\ldots{})
\chapter{Chapter}\label{chapter-9}
(\ldots{})
\chapter{Chapter}\label{chapter-10}
(\ldots{})
\end{document}
有没有使用 Rmarkdown 中的部分解决方案header-includes:
?该文件会定期进行编辑,因此我不希望直接编辑 TeX 文件。话虽如此,我很高兴了解 TeX 文件为什么会导致这种情况,这样我就可以尝试自己更改它。
答案1
好吧,我一开始没有注意到这个问题,因为它只出现在第 4 页。在学习了一些 Rmarkdown 并弄乱了 .cls 文件后,我想我找到了这个问题。首先修复,然后解释。
修复
问题在于toc: true
选项的使用。目录需要在范围内\frontmatter
,而此选项似乎可以防止这种情况发生。请改用以下内容:
---
title: ".Rmd tufte_book page numbering"
author: "Author"
documentclass: tufte
output:
tufte::tufte_book:
number_sections: true
---
\frontmatter
\tableofcontents
# Preface
\mainmatter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
# Chapter
说明
Tufte LaTeX 类中的标题设置在tufte-common.def
定义文件相关代码从1438行开始到1481行结束:
% Sets up the running heads and folios.
\RequirePackage{fancyhdr}
% Set the default page style to 'fancy'
\pagestyle{fancy}
% Set the header/footer width to be the body text block plus the margin
% note area.
\AtBeginDocument{%
\ifthenelse{\boolean{@tufte@symmetric}}
{\fancyhfoffset[LE,RO]{\@tufte@overhang}}
{\fancyhfoffset[RE,RO]{\@tufte@overhang}}
}
% The running heads/feet don't have rules
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
% The 'fancy' page style is the default style for all pages.
\fancyhf{} % clear header and footer fields
\ifthenelse{\boolean{@tufte@twoside}}
{\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plainauthor}}}%
\fancyhead[RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}}
{\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}}
% The `plain' page style is used on chapter opening pages.
% In Tufte's /Beautiful Evidence/ he never puts page numbers at the
% bottom of pages -- the folios are unexpressed.
\fancypagestyle{plain}{
\fancyhf{} % clear header and footer fields
% Uncomment the following five lines of code if you want the opening page
% of the chapter to express the folio in the lower outside corner.
%\ifthenelse{\boolean{@tufte@twoside}}
% {\fancyfoot[LE,RO]{\thepage}}
% {\fancyfoot[RE,RO]{\thepage}}
}
% The `empty' page style suppresses all headers and footers.
% It's used on title pages and `intentionally blank' pages.
\fancypagestyle{empty}{
\fancyhf{} % clear header and footer fields
}
正是这一行导致了不良行为:
{\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plainauthor}}}%
和命令会进行修改,删除前文中的部分,并\frontmatter
在主内容中替换为:\mainmatter
tufte-book.cls
\plainauthor
\plainauthor
\plaintitle
% The front matter in Tufte's /Beautiful Evidence/ contains everything up
% to the opening page of Chapter 1. The running heads, when they appear,
% contain only the (arabic) page number in the outside corner.
%\newif\if@mainmatter \@mainmattertrue
\renewcommand\frontmatter{%
\if@openright%
\cleardoublepage%
\else%
\clearpage%
\fi%
\@mainmatterfalse%
\pagenumbering{arabic}%
%\pagestyle{plain}%
\fancyhf{}%
\ifthenelse{\boolean{@tufte@twoside}}%
{\fancyhead[LE,RO]{\thepage}}%
{\fancyhead[RE,RO]{\thepage}}%
}
% The main matter in Tufte's /Beautiful Evidence/ doesn't restart the page
% numbering---it continues where it left off in the front matter.
\renewcommand\mainmatter{
\if@openright%
\cleardoublepage%
\else%
\clearpage%
\fi%
\@mainmattertrue%
\fancyhf{}%
\ifthenelse{\boolean{@tufte@twoside}}%
{% two-side
\renewcommand{\chaptermark}[1]{\markboth{##1}{}}%
\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plaintitle}}}% book title
\fancyhead[RO]{\smallcaps{\newlinetospace{\leftmark}}\quad\thepage}% chapter title
}%
{% one-side
\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}% book title
}%
}
此代码重新定义了标题以删除作者姓名并将其替换为正文中的标题,并仅打印前言中的页码(即,它似乎做了您想要的事情)。
问题是\frontmatter
在 pancdoc 生成目录之前没有调用。通过删除选项并\tableofcontents
在适当的位置(之后\frontmatter
)手动插入命令,您可以获得指定的正确标题tufte-book.cls
。