1

I'm trying to customize my TOC with etoc in book class, but I'm failing to apply MakeUppercase to \etocname. I'm using local TOCs, hyperref and fancyhdr in case that is relevant.

My main question:

  1. How do I make the \etocname respect MakeUppercase? I already tried all sorts of with/without { } combinations. I also tried this solution, but it messes up the \markboth command, that I need. This other solution works, of course, but I don't want to manually change all my parts, chapters and sections. This option doesn't work for me because I already use titlesec for formatting the in-text appearances of chapters, etc.

I also would like to know:

  1. Where can I find the etoc-like code for the standard styles in the book class? I'm currently guessing the font sizes and {start}, {finish} codes for each level in the \etocsetstyle. I couldn't find this in the etoc documentation or elsewhere.

Here is a MWE with my try for changing the Part style in TOC:

\documentclass[a4paper]{book}
\usepackage{etoc}
\etocsetstyle{part}
{\parindent 0pt
\nobreak
\etocskipfirstprefix}
{\pagebreak[3]\bigskip}
{\large\MakeUppercase\bfseries
\etocifnumbered{\etocnumber{} \ \ \  \MakeUppercase \etocname}{}\nobreak\hfill \etocpage\par}
{}


\begin{document}

\tableofcontents
\markboth{contents}{} %I need the solution to work with this

\part{A Part}
\chapter{A Chapter}
 \section{A Section} 
  \subsection{A subsection}

\end{document}

For reference, here is a pic of what I mean by "standard style", which is what I get if I load the MWE without any etocmodifications. standard TOC style

1
  • About "Where can I find the etoc-like code for the standard styles in the book class?", 29. Emulating the book class in etoc.pdf contains an answer which adds some features. Maybe you are using an old version whose documentation does not have this?
    – user691586
    Aug 31, 2023 at 6:49

2 Answers 2

0

If you could switch to memoir class, you could do

\makeatletter
\settocpreprocessor{part}{%
  \let\tempf@rtoc\f@rtoc%
  \def\f@rtoc{%
\MakeUppercase{\tempf@rtoc}}}
\makeatother

(See p. 162 of Memoir manual if you use hyperref).

Else, perhaps have a look here: Upper case chapter titles in the table of contents?

2
  • I can't use memoir, but redefining the command did work, thanks. (For those who, like me, need to discover where to find the original command: look into the [book] class file of your distribution.) It is a bit frustrating though, I thought etoc was supposed to make this sort of approach unnecessary.
    – B. Dors
    Aug 29, 2023 at 16:44
  • @B.Dors Yes, it would be useful to know wheter the implementation of etoc would allow a simpler solution. Perhaps contact directly the package mantainer? And/or unmark the answer as accepted and wait for someone more competent than I am. Aug 29, 2023 at 17:01
2

Use \etocthename in place of \etocname.

\documentclass[a4paper]{book}
\usepackage{etoc}
\etocsetstyle{part}
{\parindent 0pt
\nobreak
\etocskipfirstprefix}
{\pagebreak[3]\bigskip}
{\large\bfseries
\etocifnumbered{\etocnumber{} \ \ \  \MakeUppercase \etocthename}{}\nobreak\hfill \etocpage\par}
{}


\begin{document}

\tableofcontents
\markboth{contents}{} %I need the solution to work with this

\part{A Part}
\chapter{A Chapter}
 \section{A Section} 
  \subsection{A subsection}

\end{document}

If you use hyperref and want the part name to be hyperlinked, you will need a slightly more complex

\etoclink{\MakeUppercase \etocthename}

Complete example:

\documentclass[a4paper]{book}
\usepackage{etoc}
\etocsetstyle{part}
{\parindent 0pt
\nobreak
\etocskipfirstprefix}
{\pagebreak[3]\bigskip}
{\large\bfseries
\etocifnumbered{\etocnumber{} \ \ \  \etoclink{\MakeUppercase \etocthename}}{}\nobreak\hfill \etocpage\par}
{}

\usepackage{hyperref}
\begin{document}

\tableofcontents
\markboth{contents}{} %I need the solution to work with this

\part{A Part}
\chapter{A Chapter}
 \section{A Section} 
  \subsection{A subsection}

\end{document}

Note: I removed the first \MakeUppercase from your code.

TOC

2
  • As an aside, using \etocsetstyle{part}... triggers etoc package to use its default fall-back styles for the other levels such as chapter and section, which are not the book class ones.
    – user691586
    Aug 30, 2023 at 8:48
  • Further: the \etocifnumbered looks weird. If the part was not numbered it would choose the empty false branch, ionly \etocpage remains then, is that intended?
    – user691586
    Aug 30, 2023 at 8:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .