TransWikia.com

Modifications of chapter name in header with fancyhdr don't work in table of contents

TeX - LaTeX Asked by Plergux on June 14, 2021

I am formatting my headers and footers with fancyhdr and for some reason all my formatting comes out fine except for leftmark in the toc part of the document. I have tried with and without frontmatter, and concocted up all manner of custom definitions for fancyhdr but so far I have not hit upon the magic formula that will change EFNISYFIRLIT (Table of contents) in the header from all caps to small caps. The Author definition works fine in the toc part.

Small caps definition of Author working as expected:
enter image description here

And toc chapter header in all caps (where I would expect small caps):
enter image description here

Here is an MWE:

documentclass[12pt,a4paper,openany]{book}
usepackage{lipsum}

usepackage[LY1,T1]{fontenc} 
usepackage[utf8]{inputenc}
usepackage[icelandic]{babel}
usepackage{lmodern}
usepackage{textcomp}

usepackage{fancyhdr}
pagestyle{fancy}
renewcommand{chaptermark}[1]{%
    markboth{%
        thechapter. #1}{}}

% author definition for fancyhdr
makeatletter
newcommandAuthor{Þórhalla Guðmundsdóttir Beck}
letTitle@title
makeatother

fancyhead{}
renewcommand{headrulewidth}{0pt}
fancyhead[LO]{footnotesizescshapeAuthor}
fancyhead[RE]{footnotesizescshapeleftmark}
fancyfoot{}
fancyfoot[CO,CE]{textendash thepage textendash}

% redefinition of pagestyle{plain} for consistency in page number formatting
fancypagestyle{plain}{%
 renewcommand{headrulewidth}{0pt}%
  fancyhf{}%
  fancyfoot[CO,CE]{textendash thepage textendash}%
}

usepackage[toctitles]{titlesec}
titleformat{chapter}
{normalfontHuge}
{scshape oldstylenums{thechapter}{.}}
{1ex minus .1ex}
{normalfontHuge}
titlespacing*{chapter}
{0pt}{30pt}{16pt}

usepackage{appendix}

begin{document}

frontmatter
tableofcontents

mainmatter
chapter{One} lipsum[1-15] section{Another} bla section{Extra} bla section{Section} bla

chapter{Two} bla section{Another} bla section{Extra} bla section{Section} bla

chapter{Three} bla section{Stuff} bla

chapter{Four} bla section{Blather} bla

chapter{Five} bla section{Another} bla section{Extra} bla section{Section} bla

chapter{This} bla section{Another} bla section{Extra} bla section{Section} bla

chapter{Is} bla section{Another} bla section{Extra} bla section{Section} bla

chapter{Getting} bla section{Stuff} bla

chapter{Ridiculous} bla section{Blather} bla

chapter{Really} bla section{Another} bla section{Extra} bla section{Section} bla

chapter{Eitthvað} bla section{One} bla section{Extra} bla section{Section} bla

chapter{Meira} bla section{Another} bla section{Extra} bla section{Section} bla

chapter{Kjaftæði} bla section{Stuff} bla

chapter{Hér} bla section{Blather} bla

chapter{Fyrir} bla section{Another} bla section{Extra} bla section{Section} bla

chapter{Efnis} bla section{Another} bla section{Extra} bla section{Section} bla

chapter{Yfir} bla section{Another} bla section{Extra} bla section{Section} bla

chapter{Lit} bla section{Stuff} bla

chapter{Andvarp} bla section{Blather} bla

chapter{Stuna} bla section{Another} bla section{Extra} bla section{Section} bla

begin{appendices}
providecommand{appendixname}{Viðauki}{thechapter}
titleformat{chapter}{itshapehuge}{appendixname{} thechapter.}{20pt}{normalfonthuge}

chapter{Alpha} bla

chapter{Beta} bla

end{appendices}

end{document}

One Answer

The definition of tableofcontents necessarily sets the left and right marks using MakeUppercase; here's the formal definition from book.cls:

newcommandtableofcontents{%
    if@twocolumn
      @restonecoltrueonecolumn
    else
      @restonecolfalse
    fi
    chapter*{contentsname
        @mkboth{%
           MakeUppercasecontentsname}{MakeUppercasecontentsname}}%
    @starttoc{toc}%
    if@restonecoltwocolumnfi
    }

The easiest solution would be to redefine MakeUppercase temporarily to scshape (assuming it's not used elsewhere within the ToC):

begingroup
renewcommand{MakeUppercase}{scshape}
tableofcontents
endgroup

enter image description here

Correct answer by Werner on June 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP