3

I like to have my chapter, section and subsection headings in small caps with no capitalised first letters, e.g. written as 'chapter heading name' rather than 'Chapter Heading Name' in the code itself. However, using default settings this translates in the table of contents as, obviously, 'chapter heading name'.

I am aware I could likewise use small caps in the table of contents but I wish to revert back to normal, capitalised text. I am having trouble doing this. I found that you can use \usepackage{mfirstuc} and then use the command \capitalisewords in the \titlecontents{chapter}, \titlecontents{section} and \titlecontents{subsection} options of the titletoc package.

However, the first letter of the first word is not capitalised in the table of contents, yet the other first letters on each subsequent word are! Bizarrely, if I capitalise the first letter of the first word of my chapter, section and subsection headings in the text, then the first letter of the first word of each chapter, section and subsection in the table of contents is now indeed capitalised.

I feel this is something fundamental to how TeX works and I need to tweak something else.

See MWE below:

\documentclass[10pt,a4paper]{book}

\usepackage{titlesec,titletoc}

% In the following I ensure chapter, section and subsection headings are small caps via \scshape command
\titleformat{\chapter}[display]{\sf}{Chapter \thechapter}{2mm}{\scshape}
\titleformat{\section}[hang]{\rm\scshape}{\thesection}{4mm}{}
\titleformat{\subsection}[hang]{\rm\scshape}{\thesubsection}{4mm}{}

\usepackage{mfirstuc} % <--- this package used to capitalise first words via \capitalisewords command

\titlecontents{chapter}
[0pt]                                               
{}
{\contentsmargin{0pt}                               
    \thecontentslabel\enspace
    \capitalisewords} % <---
{\contentsmargin{0pt}\large}                        
{\titlerule*[.5pc]{.}\contentspage}                 
[]  

\titlecontents{section}
[0pt]                                               
{}
{\contentsmargin{0pt}                               
    \thecontentslabel\enspace
    \capitalisewords} % <---
{\contentsmargin{0pt}\large}                        
{\titlerule*[.5pc]{.}\contentspage}                 
[]     

\titlecontents{subsection}
[0pt]                                               
{}
{\contentsmargin{0pt}                               
    \thecontentslabel\enspace
    \capitalisewords} % <---
{\contentsmargin{0pt}\large}                        
{\titlerule*[.5pc]{.}\contentspage}                 
[]     

\begin{document}

\tableofcontents

\chapter{my first chapter} % if changed to 'My first chapter' then it works
\section{my first section} % if changed to 'My first section' then it works
\subsection{my first subsection} % if changed to 'My first subsection' then it works

\end{document}

Output: output

2
  • Is this what you’re looking for?
    – Davislor
    Mar 14, 2021 at 14:49
  • I saw this earlier and is where I got \usepackage{mfirstuc} from. All the solutions posted there (which actually do something in my code) do the exact same thing, i.e. the first letter of the first word is not capitalised.
    – WilldoesR
    Mar 14, 2021 at 15:40

2 Answers 2

1

There is some code being inserted before the title, preventing \capitalisewords from recognizing my as a word.

The \capitalisefmtwords* command is able to parse this correctly.

\documentclass[10pt,a4paper]{book}

\usepackage{titlesec,titletoc}

% In the following I ensure chapter, section and subsection headings are small caps via \scshape command
\titleformat{\chapter}[display]{\sf}{Chapter \thechapter}{2mm}{\scshape}
\titleformat{\section}[hang]{\rm\scshape}{\thesection}{4mm}{}
\titleformat{\subsection}[hang]{\rm\scshape}{\thesubsection}{4mm}{}

\usepackage{mfirstuc} % <--- this package used to capitalise first words via \capitalisewords command

\titlecontents{chapter}
[0pt]                                               
{}
{\contentsmargin{0pt}                               
    \thecontentslabel\enspace
    \capitalisefmtwords*} % <---
{\contentsmargin{0pt}\large}                        
{\titlerule*[.5pc]{.}\contentspage}                 
[]  

\titlecontents{section}
[0pt]                                               
{}
{\contentsmargin{0pt}                               
    \thecontentslabel\enspace
    \capitalisefmtwords*} % <---
{\contentsmargin{0pt}\large}                        
{\titlerule*[.5pc]{.}\contentspage}                 
[]     

\titlecontents{subsection}
[0pt]                                               
{}
{\contentsmargin{0pt}                               
    \thecontentslabel\enspace
    \capitalisefmtwords*} % <---
{\contentsmargin{0pt}\large}                        
{\titlerule*[.5pc]{.}\contentspage}                 
[]     

\begin{document}

\tableofcontents

\chapter{my first chapter} % if changed to 'My first chapter' then it works
\section{my first section} % if changed to 'My first section' then it works
\subsection{my first subsection} % if changed to 'My first subsection' then it works

\end{document}
7
  • This solved it. Many thanks.
    – WilldoesR
    Mar 15, 2021 at 9:29
  • 1
    For those who later see this, \MFUnocap{} can be used to not capitalise certain words such as 'a', 'and', 'the' etc.
    – WilldoesR
    Mar 15, 2021 at 9:37
  • I don't suppose you know how to force capitalisation of each letter for specific words. For example, if I use initialisms and acronyms in some of my section headings such as NASA, USA, EU etc., I would write these as nasa, usa, eu, but I want all of them capitalised in the table of contents. This seems a lot harder, unless there's some command that will force capitalisation on words you define?
    – WilldoesR
    Mar 16, 2021 at 15:34
  • @WilldoesR Some possible approaches: 1: Capitalize the chapter title like you want it to appear in the ToC, and have the chapter formatting lowercase it before applying small caps. That’s much simpler than starting with lowercase and trying to programmatically determine which letters to capitalize. (You could also mix caps and small caps.)
    – Davislor
    Mar 16, 2021 at 16:11
  • @WilldoesR 2: Provide an alternative title for the ToC, like \chapter{foo}[Foo].
    – Davislor
    Mar 16, 2021 at 16:11
1

You write the division titles in the document in lower case and print them in small caps. Why not just set the ToC entries in small caps? The tocloft package enables you to do that (and many other ToC adjustments).

% capitaliseprob.tex  SE 587274

\documentclass[10pt,a4paper]{book}

\usepackage{comment}

%%%%%% PW code for setting the ToC
\usepackage{tocloft}

\renewcommand{\cfttoctitlefont}{\scshape} % small caps for ToC title
% In the book class, chapter entries in the ToC are  bold, no dotted leader
\renewcommand{\cftchapfont}{\scshape} % chapter titles in small caps
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % not bold but dotted
\renewcommand{\cftchappagefont}{} % not bold page number
\renewcommand{\cftsecfont}{\scshape} % small caps for section titles
\setlength{\cftsecindent}{0em} % no indentation of section entries
% and similary for subsections
\renewcommand{\cftsubsecfont}{\scshape}
\setlength{\cftsubsecindent}{0em}
%\usepackage{titletoc} % done via tocloft
%%%%% end of PW code

\usepackage{titlesec}

% In the following I ensure chapter, section and subsection headings are small caps via \scshape command
\titleformat{\chapter}[display]{\sf}{Chapter \thechapter}{2mm}{\scshape}
\titleformat{\section}[hang]{\rm\scshape}{\thesection}{4mm}{}
\titleformat{\subsection}[hang]{\rm\scshape}{\thesubsection}{4mm}{}

\begin{comment}
%%% comment out some of the OP's original code

\usepackage{mfirstuc} % <--- this package used to capitalise first words via \capitalisewords command

\titlecontents{chapter}
[0pt]                                               
{}
{\contentsmargin{0pt}                               
    \thecontentslabel\enspace
    \capitalisewords} % <---
{\contentsmargin{0pt}\large}                        
{\titlerule*[.5pc]{.}\contentspage}                 
[]  

\titlecontents{section}
[0pt]                                               
{}
{\contentsmargin{0pt}                               
    \thecontentslabel\enspace
    \capitalisewords} % <---
{\contentsmargin{0pt}\large}                        
{\titlerule*[.5pc]{.}\contentspage}                 
[]     

\titlecontents{subsection}
[0pt]                                               
{}
{\contentsmargin{0pt}                               
    \thecontentslabel\enspace
    \capitalisewords} % <---
{\contentsmargin{0pt}\large}                        
{\titlerule*[.5pc]{.}\contentspage}                 
[]     

\end{comment}

\begin{document}

\tableofcontents

\chapter{my first chapter} % if changed to 'My first chapter' then it works
\section{my first section} % if changed to 'My first section' then it works
\subsection{my first subsection} % if changed to 'My first subsection' then it works

\end{document}

enter image description here

3
  • Also, LaTeX lets you give an alternative title to appear in the Table of Contents.
    – Davislor
    Mar 14, 2021 at 19:13
  • Or you could have the titleformat lowercase it and apply small-caps, instead of having the table of contents try to titlecase it.
    – Davislor
    Mar 14, 2021 at 19:15
  • Unsure if you understood my question, but I apologise if I misunderstand your answer. I wanted my headings to be small caps in the main body but be normal, capitalised text (not small caps) in the table of contents. As I am using small caps, I write my headings in my code without any capitals, so this translates over in the table of contents as normal, uncapitalised text If I do not use a package to capitalise each word.
    – WilldoesR
    Mar 15, 2021 at 9:33

You must log in to answer this question.

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