I am using the university thesis template which has the chapter/section headings setup in a way that prevents using hyperref
. The problem is they use \setcounter{secnumdepth}{0}
so there is no section number preceding the chapter/section title. They want the heading to display using this format both in the TOC and at the beginning of the chapter:
Chapter 1: Sample Chapter Heading
The way they implement this means we must manually number the chapters and it also breaks hyperref
.
Here is a MWE:
\documentclass[12pt]{article}
\usepackage{setspace}
\setcounter{secnumdepth}{0}
\usepackage{tocstyle}
\usetocstyle{standard}
\renewcommand{\contentsname}{\centerline {\normalsize Table of Contents}}
\usepackage{tocloft}
\renewcommand{\cftsecfont}{\normalsize}
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}
\renewcommand\cftloftitlefont{\normalsize}
\renewcommand\cftlottitlefont{\normalsize}
\usepackage{sectsty}
\sectionfont{\centering\normalsize}
% this breaks their chapter/toc settings
% \usepackage[hidelinks]{hyperref}
\begin{document}
\newpage
\tableofcontents
\newpage
%\section{\protect \centering Chapter 7: Sample Title}
\section{\protect Chapter 7: Sample Title}
chapter text goes here
\end{document}
I am sure latex has the ability to create chapter/section heading in this format while using counters but I am struggling to get it to work. How can I use the built in counters (preferably the section counter since each section is a chapter in their setup) to natively create this format of the table of contents which would also allow the use of hyperref
?
EDIT 1:
I did find that the \centering
flag in the section titles was conflicting with hyperref. Following these two responses (thanks @GonzaloMedina), I was able to implement the centering and the desired font size using the following
\usepackage{sectsty}
\sectionfont{\centering\normalsize\selectfont}
in the preamble which allowed me to remove the \centering
flag from the section title:
%\section{\protect \centering Chapter 7: Sample Title}
\section{\protect Chapter 7: Sample Title}
I added these modifications (commenting out the original) in the MWE.
hyperref
by removing\protect \centering
. To get the right chapter labels, use\renewcommand\thesection{Chapter \arabic{section}:}
\renewcommand\thesection{Chapter \arabic{section}:}
was exactly what I needed. Thank you! (can you add that as an answer so I can accept that?)