[Tex/LaTex] tufte_book: prevent page numering & author in ToC (Rmarkdown)

authorpage-numberingtable of contentstufte

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:

enter image description here

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:

---
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

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:

% 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
}

It's really this line that's causing the undesired behavior:

{\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plainauthor}}}%

The \frontmatter and \mainmatter commands in tufte-book.cls make alterations that removes \plainauthor in front matter, and replaces \plainauthor with \plaintitle in the main matter:

% 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
    }%
}

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 by tufte-book.cls.