I am creating a template for use in Report document class with pdfLaTeX compiler in Overleaf.
There are a lot of formatting details, but I think I have them all minimally reproduced in the code below.
I have five questions on formatting the table of contents; think they are all related, so I grouped them in the same post:
- How can I center, capitalize the word "Contents", and specify the font size? I am currently doing
\renewcommand{\contentsname}{\centering\fontsize{18pt}{0pt}\MakeUppercase{\textbf{contents}}}, which does not apply the centering and is bad practice based on the answers here and here. I understand why this is bad practice, but I don't understand the correct way to do it. (I intend to apply this to have the same formatting for the "List of Figures" header.) - The TOC currently makes most parts bold, which I like. How can I also make sections (but not subsections) bold in the TOC?
- How can I make chapter titles and sections (but not subsections) in all caps?
- How can I add page number dots to Abstract, List of Figures, etc. on the TOC, that are in the same format (spacing) as the other dots? Can I make all the dots denser? (to meet Word template requirements)
- Using
\addcontentsline{toc}{chapter}{\MakeUppercase{Table of Contents}}works fine in this stand-alone example, but for some reason it throws an error in my real template. It compiles correctly, but I want to get rid of the error. I can't find any difference that would cause it. Error:Undefined control sequence. The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}. Learn more **\MakeUppercase ...ppercaseUnsupportedInPdfStrings** The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., \hobx'), type I' and the correct spelling (e.g., I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.Based on the answer here, I think I need to use\texorpdfstring{}, but I tried some combinations with that and they didn't compile.
%-------------------------------------------------------
% Dummy Chapter 1
\begin{filecontents*}{ChapterA.tex}
\chapter{Introduction}
\lipsum[1]
\section{Section Name}
Here is some text, see Figure \ref{fig:a}.
\begin{figure}
\centering
\includegraphics[width = 0.5\textwidth]{example-image-a}
\caption{An example figure.}
\label{fig:a}
\end{figure}
\subsection{Subsection Name}
Here is a subsection, see \cite{einstein1906new}.
\end{filecontents*}
%-------------------------------------------------------
% Dummy Abstract
\begin{filecontents}{Abstract.tex}
\begin{center}
{\fontsize{18pt}{0pt}\MakeUppercase{\textbf{abstract}}}
\vspace{24pt}
\end{center}
\addcontentsline{toc}{chapter}{\MakeUppercase{Abstract}}
This is the abstract.
\end{filecontents*}
%-------------------------------------------------------
% Dummy References
\begin{filecontents}{refs.bib}
@article{einstein1906new,
title={A new determination of molecular dimensions},
author={Einstein, Albert},
journal={Ann. Phys.},
volume={19},
pages={289--306},
year={1906}
}
\end{filecontents}
%-------------------------------------------------------
% Preamble
\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{lipsum}
% set page and paragraph dimensions
\setlength{\parindent}{0.5in}
\setlength{\parskip}{6pt}
% set report font
\usepackage[sfdefault]{carlito}
% format headers
\usepackage{titlesec}
\titleformat{\chapter}%
{\normalfont\fontsize{22pt}{0pt}\bfseries}%
{\thechapter}{0.5in}{}
\titlespacing*{\chapter}{0pt}{80pt}{40pt}
\titleformat{\section}%
{\normalfont\fontsize{14pt}{0pt}\bfseries}%
{\thesection}{0.5in}{\MakeUppercase}
\titlespacing*{\section}{0pt}{24pt}{12pt}
\titleformat{\subsection}%
{\normalfont\fontsize{14pt}{0pt}\bfseries}%
{\thesubsection}{0.5in}{}
\titlespacing*{\subsection}{0pt}{18pt}{12pt}
% set-up frontmatter, mainmatter, backmatter
\makeatletter
\newcommand\frontmatter{
\cleardoublepage
\pagenumbering{roman}}
\newcommand\mainmatter{
\cleardoublepage
\pagenumbering{arabic}}
\newcommand\backmatter{
\if@openright
\cleardoublepage
\else
\clearpage
\fi
}
\makeatother
% format references fonts, etc.
\AtBeginEnvironment{thebibliography}{%
\titleformat{\chapter}%
{\normalfont\fontsize{14pt}{0pt}\bfseries\filcenter}%
{\thechapter}{0.5in}{\MakeUppercase}%
\titlespacing*{\chapter}{0pt}{0pt}{12pt}
}
\renewcommand{\bibname}{References}
\AddToHook{cmd/bibsection/after}{%
\addcontentsline{toc}{chapter}{\bibname}%
}
\def\bibfont{\fontsize{11pt}{0pt}\selectfont\hyphenpenalty=10000}
% format TOC
\renewcommand{\contentsname}{%
\centering\fontsize{18pt}{0pt}%
\MakeUppercase{\textbf{contents}}}
%-------------------------------------------------------
% Begin
\begin{document}
\title{test}
\author{none}
\date{\today}
\frontmatter
\include{Title}
\include{Abstract}
\tableofcontents
\addcontentsline{toc}{chapter}{Contents}
\listoffigures
\addcontentsline{toc}{chapter}{List of Figures}
\mainmatter
\include{ChapterA}
\backmatter
\bibliographystyle{abbrvnat}
\bibliography{refs}
\end{document}
%-------------------------------------------------------



\usepackage{hyperref}and\hypersetup{colorlinks=true, linkcolor=blue, citecolor=blue}to the preamble, it causes an undefined control sequence error and "breaks" the compiled pdf – a11 Nov 04 '21 at 13:09\usepackage[linktocpage=true]{hyperref}works – a11 Nov 04 '21 at 15:49hyperrefis pretty critical, since it taps into many elements of the document creation and may not just work with any custom changes... did you loadhyperreflast? – Werner Nov 04 '21 at 15:58[linktocpage=true]option... and now it seems fine regardless of where it is loaded... – a11 Nov 04 '21 at 16:01