4

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.

2
  • 1
    My guess would be it's in the tufte-book class file header definitions. I'm not at a computer to check, but you might take a look at the documentation for the class file and see how to alter headings. If RMarkdown enables you to redefine TeX commands, you can probably pass the fix through RMarkdown.
    – Dennis
    Oct 9 '17 at 0:39
  • @Dennis Thank you, this is helpful. I hadn't considered the .cls file yet. I'm not very familiar with class files, so if someone beats me to finding it, I would appreciate it. Oct 10 '17 at 3:08
3
+50

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.

5
  • 1
    Wow, this is very helpful! Thank you very much for also including an explanation! Oct 11 '17 at 13:51
  • @FransRodenburg Out of curiosity, is the toc option recommend with Tufte? Or is it something that's a general purpose option for any TeX class or, e.g., HTML. Because it does seem like it should "know" that the ToC goes in the front matter.
    – Dennis
    Oct 11 '17 at 17:10
  • Do you mean the toc option in Rmarkdown? It is an option that works with most output in Rmarkdown, including HTML and pdf. I'm not sure about tufte_book, but interestingly enough, it is recommended for tufte handout (rmarkdown.rstudio.com/tufte_handout_format.html#intermediate_tex) Oct 11 '17 at 22:42
  • 1
    @FransRodenburg I did a bit of digging but gave up after a while. I think the issue is that pandoc v. 1.18 deprecated the --chapters option (which is what's being used when I compile the PDF in RStudio) in favor of --top-level-division=chapter. Since letter classes (like tufte-handout) have sections as their top level sectioning command, and no \frontmatter command, I suspect that use of the deprecated --chapters is causing pandoc to default to....
    – Dennis
    Oct 12 '17 at 21:54
  • 1
    \section as the top-level command and so preventing it from recognizing the \chapter structure when it decides where to insert the ToC.
    – Dennis
    Oct 12 '17 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.