When using Rmarkdown to create a tufte_book pdf, the page numbering somehow causes the author to be displayed at the top of the page in the table of contents as follows:
I would like to remove it, or replace it with the book title. The numbering in the ToC itself is also distracting, so I would like to remove that as well, while keeping the numbering in the preface and main matter.
I have tried to find what causes this in the TeX file, but I cannot find it.
Below is a minimal working example in 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
And the resulting TeX file:
\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}
Is there a solution for this using the header-includes:
part in Rmarkdown? The file undergoes regular edits, so I would prefer not to edit the TeX file directly. That being said, I would be happy to understand why the TeX file results in this, so I can try and change it myself.
Best Answer
Ok, so I didn't notice the issue at first since it only occurs on page 4. After learning a bit of Rmarkdown and messing about in the .cls files I think I found the issue. First the fix, then the explanation.
The Fix
The issue is with the use of the
toc: true
option. The table of contents needs to be in the scope of\frontmatter
, and this option seems to prevent that. Instead use the following:The Explanation
Headers in the Tufte LaTeX classes are set in the
tufte-common.def
definitions file. The relevant code begins at line 1438 and ends at 1481:It's really this line that's causing the undesired behavior:
The
\frontmatter
and\mainmatter
commands intufte-book.cls
make alterations that removes\plainauthor
in front matter, and replaces\plainauthor
with\plaintitle
in the main matter:This code redefines the header to remove the author name and replace it with the title in the main matter, and print only the page number in the front matter (i.e., it seems to do what you want).
The issue is that
\frontmatter
isn't being invoked before pancdoc generates the ToC. By removing the option and manually inserting the\tableofcontents
command in the appropriate place (after\frontmatter
) you obtain the correct headers as specified bytufte-book.cls
.