1

I am using sectsty and titlecaps packages to convert my section headings into title case. But, table of content remains unchanged. I want to see my table of contents also in title case.

Here is MWE

\documentclass{book} % The default font size and one-sided printing (no margin offsets)


% packages for setting section headings to titles caps 
\usepackage{sectsty}
\usepackage{titlecaps}

\sectionfont{\titlecap}
\subsectionfont{\titlecap}
\subsubsectionfont{\titlecap}

\begin{document}

\tableofcontents

\section{This should be in upper case}
It is!
\subsection{a sub section}
here it is
\subsubsection{a sub sub section}
here it is

\section{This should \o be in title case}
It is!
\end{document}
  • Welcome to TeX - LaTeX! Probably you should be looking at titlesec and titletoc to help with this. But it is not straightforward. – Andrew Swann Aug 20 '18 at 7:36
2

Replacing the \sectionfont and \subsectionfont with

\let\oldsection\section
\def\section#1{\oldsection{\titlecap{#1}}}
\let\oldsubsection\subsection
\def\subsection#1{\oldsubsection{\titlecap{#1}}}

yields:

enter image description here

Code:

\documentclass{book} % The default font size and one-sided printing (no margin offsets)


% packages for setting section headings to titles caps 
\usepackage{sectsty}
\usepackage{titlecaps}

%\sectionfont{\titlecap}
%\subsectionfont{\titlecap}
\subsubsectionfont{\titlecap}

\let\oldsection\section
\def\section#1{\oldsection{\titlecap{#1}}}
\let\oldsubsection\subsection
\def\subsection#1{\oldsubsection{\titlecap{#1}}}

\begin{document}

\tableofcontents

\section{This should be in upper case}
It is!
\subsection{a sub section}
here it is
\subsubsection{a sub sub section}
here it is

\section{This should \o be in title case}
It is!

\subsection{er\"ods-r\'enyi random graph model}

\end{document}
  • It is working fine except when subsection heading contains some special character such as "Er\"ods-R\'enyi Random Graph Model". any idea how to solve it? – mqpasta Aug 20 '18 at 8:38
  • @mqpasta: I am unable to reproduce the problem. See updated answer which include this case. – Peter Grill Aug 21 '18 at 9:02
  • Perhaps OP means it does not work with øbe in place of \o be? – user4686 Aug 25 '18 at 8:48

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.