1

I recently got help for formatting subsections numbers without changing reference numbers. (How to indent subsections in text without affecting references?) which did just what I had asked.

Unfortunately, my working example included neither a book table of contents nor a chapter table of content and I just found out that both the book toc and the chapter toc list the subsections which I don't want.

Also, there are weird things: the chapter 1 toc starts with "chapter.1" and while the chapter 2 toc should be empty it is an unformatted copy of the chapter 1 toc (along with the "chapter.1" up front.)

None of which, of course, may have anything to do with the formatting code that was suggested.

Here is a MWE:

\documentclass[11pt]{book}
\usepackage{titlesec} 
    \titleformat{\subsection}[runin]{\normalfont\large\bfseries}{\hspace{10mm}\arabic{subsection}.}{1mm}{}{}
\usepackage[hyperfootnotes=false]{hyperref}%
\usepackage{cleveref}%
    \Crefname{subsection}{Subsection}{Subsections}  
\usepackage[dotinlabels]{titletoc}
    \titlecontents{chapter}[6pc]{\addvspace{1pc}\bfseries\filright}{\contentslabel[\chaptername\ \thecontentslabel]{6pc}}{}{\hfill\contentspage}[\addvspace{2pt}]%
    \newcommand\xquad{\hspace{0.4em plus .2em minus .2em}}%
    \titlecontents*{p-section}[0pt]{\filright\small}{}{}{,\thecontentspage}[\xquad\textbullet\xquad][.]%
    \newcommand{\ChapterToc}{\startcontents[chapters]\printcontents[chapters]{p-}{1}{}\vspace{10mm}}%

\begin{document}
         \tableofcontents

\chapter{Numbers}\label{1-0-0}
\ChapterToc

Some prefatory text
\section{Plain Numbers}\label{1-1-0}
\subsection{Definition}\label{1-1-1}
text text text text text text  
\subsection{Properties}\label{1-1-2}
text text text text text text  

\section{Signed Numbers}\label{1-2-0}
text text text text text text text text text text text text text text 
\subsection{Definition}\label{1-2-1}
text text text text text text  
\subsection{Properties}\label{1-2-2}
text text text text text text  


\chapter{Functions}\label{2-0-0}
\ChapterToc

Some text and now some references:

\Cref{1-0-0} \nameref{1-0-0}

\Cref{1-1-0} \nameref{1-1-0}

\Cref{1-1-1} \nameref{1-1-1}

\end{document}

and here is the output:

enter image description here

5
  • Please tell us which document class you use.
    – Mico
    Aug 1, 2017 at 16:07
  • @Mico Just realized!!!!
    – schremmer
    Aug 1, 2017 at 16:09
  • 1
    @schremmer: Load hyperref after titletoc and cleveref even after hyperref. It's a well-known fact that cleveref should be loaded as last package, in 99.9% of all cases
    – user31729
    Aug 1, 2017 at 16:45
  • 1
    The extra texts like chapter.1 etc. are the remains from the wrong references/addcontentsline writings due to the fact that cleveref is loaded too early
    – user31729
    Aug 1, 2017 at 17:03
  • I know and I forget. Sorry about that. The weird things are now gone thanks to your reminding me once again.
    – schremmer
    Aug 1, 2017 at 23:06

1 Answer 1

4

As already mentioned by Christian you have to load all packages except cleveref before hyperref. cleveref should be loaded after hyperref.

If only the chapter tocs should not list the subsections, then you can use the last argument of \printcontents to change tocdepth locally:

\printcontents[chapters]{p-}{1}{\setcounter{tocdepth}{1}}

enter image description here

Code:

\documentclass[11pt]{book}
\usepackage{titlesec} 
    \titleformat{\subsection}[runin]{\normalfont\large\bfseries}{\hspace{10mm}\arabic{subsection}.}{1mm}{}{}

\usepackage[dotinlabels]{titletoc}
    \titlecontents{chapter}[6pc]{\addvspace{1pc}\bfseries\filright}{\contentslabel[\chaptername\ \thecontentslabel]{6pc}}{}{\hfill\contentspage}[\addvspace{2pt}]%
    \newcommand\xquad{\hspace*{0.4em plus .2em minus .2em}}%
    \titlecontents*{p-section}[0pt]{\filright\small}{}{}{, \thecontentspage}[\xquad\textbullet\xquad][.]%
    \newcommand{\ChapterToc}{\startcontents[chapters]\printcontents[chapters]{p-}{1}{\setcounter{tocdepth}{1}}\vspace{10mm}}%

\usepackage[hyperfootnotes=false]{hyperref}%
\usepackage{cleveref}% should be the last package
    \Crefname{subsection}{Subsection}{Subsections}

\begin{document}
\tableofcontents
\chapter{Numbers}\label{1-0-0}
\ChapterToc
Some prefatory text
\section{Plain Numbers}\label{1-1-0}
\subsection{Definition}\label{1-1-1}
text text text text text text  
\subsection{Properties}\label{1-1-2}
text text text text text text  
\section{Signed Numbers}\label{1-2-0}
text text text text text text text text text text text text text text 
\subsection{Definition}\label{1-2-1}
text text text text text text  
\subsection{Properties}\label{1-2-2}
text text text text text text  

\chapter{Functions}\label{2-0-0}
\ChapterToc
Some text and now some references:

\Cref{1-0-0} \nameref{1-0-0}

\Cref{1-1-0} \nameref{1-1-0}

\Cref{1-1-1} \nameref{1-1-1}
\end{document}

If the subsections should be removed from all tocs, then change tocdepth globally:

\documentclass[11pt]{book}
\usepackage{titlesec} 
    \titleformat{\subsection}[runin]{\normalfont\large\bfseries}{\hspace{10mm}\arabic{subsection}.}{1mm}{}{}

\usepackage[dotinlabels]{titletoc}
    \titlecontents{chapter}[6pc]{\addvspace{1pc}\bfseries\filright}{\contentslabel[\chaptername\ \thecontentslabel]{6pc}}{}{\hfill\contentspage}[\addvspace{2pt}]%
    \newcommand\xquad{\hspace*{0.4em plus .2em minus .2em}}%
    \titlecontents*{p-section}[0pt]{\filright\small}{}{}{, \thecontentspage}[\xquad\textbullet\xquad][.]%
    \newcommand{\ChapterToc}{\startcontents[chapters]\printcontents[chapters]{p-}{1}{}\vspace{10mm}}%

\usepackage[hyperfootnotes=false]{hyperref}%
\usepackage{cleveref}% should be the last package
    \Crefname{subsection}{Subsection}{Subsections}

\setcounter{tocdepth}{1}% <- only parts, chapters and sections in tocs
\begin{document}
\tableofcontents
\chapter{Numbers}\label{1-0-0}
\ChapterToc
Some prefatory text
\section{Plain Numbers}\label{1-1-0}
\subsection{Definition}\label{1-1-1}
text text text text text text  
\subsection{Properties}\label{1-1-2}
text text text text text text  
\section{Signed Numbers}\label{1-2-0}
text text text text text text text text text text text text text text 
\subsection{Definition}\label{1-2-1}
text text text text text text  
\subsection{Properties}\label{1-2-2}
text text text text text text  

\chapter{Functions}\label{2-0-0}
\ChapterToc
Some text and now some references:

\Cref{1-0-0} \nameref{1-0-0}

\Cref{1-1-0} \nameref{1-1-0}

\Cref{1-1-1} \nameref{1-1-1}
\end{document}
5
  • The chapter tocs are now fine. How about the book toc? (You give them a hand and they grab your arm.)
    – schremmer
    Aug 1, 2017 at 23:07
  • Change tocdepth globally. See my updated answer.
    – esdd
    Aug 2, 2017 at 6:13
  • Perfect! But now I can't figure out how to indent the subsections in the text , e.g. 1. Definition text text text, which I used to do with \renewcommand\thesubsection{\hspace{10mm}\arabic{subsection}.} next to which I had written myself a comment, "%Also reformatted with titlesec" which does not help anymore.
    – schremmer
    Aug 2, 2017 at 16:02
  • Sorry, I forgot the \hspace{10mm} in \titleformat{\subsection}.... Now it is added again.
    – esdd
    Aug 3, 2017 at 14:23
  • I had added it of course but, in fact, nothing I had been doing in titleformat{..., like changing the size of the title, had had any effect. So I wanted to see what you would do. Only now, after you just added the hspace, I tried to comment out titleformat altogether. Still no change!!!! So, it finally dawned onto me that I must have another usepackage{titlesec}and titleformat earlier in my (very long and very complex) preamble. And, sure enough ... How dumb can one be when one doe not really know what one is doing! In any case, now ALL is well. Thanks for your GREAT patience.
    – schremmer
    Aug 4, 2017 at 12:11

You must log in to answer this question.

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