2

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.

toc image

3
  • 1
    I'm not exactly sure what your question is. You can use hyperref by removing \protect \centering. To get the right chapter labels, use \renewcommand\thesection{Chapter \arabic{section}:}
    – alaferg
    Jun 2, 2015 at 17:21
  • @alaferg, \renewcommand\thesection{Chapter \arabic{section}:} was exactly what I needed. Thank you! (can you add that as an answer so I can accept that?) Jun 2, 2015 at 18:07
  • sure, no prob :)
    – alaferg
    Jun 3, 2015 at 19:40

1 Answer 1

1

To get the right chapter labels, use

\renewcommand\thesection{Chapter \arabic{section}:}

EDIT @Werner makes an excellent point. Here's a better approach (may need to play around with the spacing) which won't mess up your labels and references. To change TOC appearance

\usepackage{tocloft}
\renewcommand{\cftsecpresnum}{Chapter }
\renewcommand{\cftsecnumwidth}{5.75em}
\renewcommand{\cftsecaftersnum}{:}

To change section heading inside doc

\usepackage{titlesec}
\titleformat{\section}{\bfseries\Large}{Chapter \arabic{section}:}{0.5em}{}
2
  • 2
    Hmmm, this will also affect reference made to chapters, not just the labels in the ToC. So, See \ref{ch:label}. will turn into See Chapter 2:., say... not really ideal.
    – Werner
    Jun 3, 2015 at 20:28
  • I think, this should edited and improved
    – user31729
    Jun 3, 2015 at 20:29

You must log in to answer this question.

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