0

I am trying to make the subsection entries in a TOC to be grouped together as a paragraph, as provided by the \titlecontents* command in the titletoc package. See my attempt in this MWE:

\documentclass[12pt]{tufte-book}
%\usepackage{titletoc} % Don't need---included with tufte-book

\titlecontents*{subsection}[.5in] {\addvspace{.5pc}\small\itshape}{}{}{~~\thecontentspage}[\ \ \ \ ]

\begin{document}

\frontmatter \setcounter{tocdepth}{2} \tableofcontents

\mainmatter

\chapter{A boring chapter}

\section{A first section}

% Words in section title are separated by ~ to prevent line breaks in titles \subsection{Corvids~and~jays}

\subsection{Elephants~and~cetaceans}

\subsection{Rosids~and~arachnids}

\end{document}

In the document produced, the subsection title "Rosids and arachnids" is broken across a line, with "arachnids" hyphenated:

enter image description here

I want to force the entire subsection title to go to the next line rather than span it.

I believe the interaction between the titletoc package and the tufte-book class affects this, since tufte-book requires titletoc and I wasn't able to reproduce the problem in a MWE that doesn't use tufte-book.

None of the solutions involving \raggedright or \hyphenpenalty suggested in answers to related questions have worked---again, I suspect it is the tufte-book document class that is the factor. Can anyone shed some light on this?

1 Answers1

0

What do you think of this? I inserted \raggedright after \itshape, and added \mbox to keep the titles together. I see that the subsection content is placed at the left margin, and I still have to figure out how to bring it back to the more right position.

\documentclass[12pt]{tufte-book}
%\usepackage{titletoc} % Don't need---included with tufte-book

\titlecontents*{subsection}[.5in] {\addvspace{.5pc}\small\itshape}{}{}{~~\thecontentspage}[\
\ \ ]

\begin{document}

\frontmatter \setcounter{tocdepth}{2} \tableofcontents

\mainmatter

\chapter{A boring chapter}

\section{A first section}

% Words in section title are separated by ~ to prevent line breaks in titles \subsection{Corvids~and~jays}

\subsection{\mbox{Elephants~and~cetaceans}}

\subsection{\mbox{Rosids~and~arachnids}}

\subsection{\mbox{Rosids~and~flowers}}

\subsection{\mbox{Rosids~and~anything else}}

\subsection{\mbox{Rosids~and~even more to do}}

\subsection{\mbox{Rosids~and~how far we should go}}

\subsection{\mbox{Rosids~and~the end of the textwidth}}

\end{document}

titlecontents protected with mbox

C. Peters
  • 1,297
  • I tried out your two changes (\raggedright and \mbox) separately. Putting\raggedright at the end of the "above code" parameter overrides the left placement, as shown in your example. The \mbox works by itself without changing the left placement. However, I don't understand these effects, such as why \raggedright overrides the left placement. Is there any explanation in terms of titletoc's options? – Thomas VanDrunen May 29 '21 at 12:41
  • Indeed, you can use the \mbox. I do not know, why it did not work the first time when I compiled twice. \raggedright in general ignores previous indentation. At https://tex.stackexchange.com/questions/35933/indenting-a-whole-paragraph I found this solution to restore the indentation after it: \parshape 1 1.5cm \dimexpr\linewidth-2cm\relax. I deleted the \raggedright in my answer. So, if \mbox for you is the solution, please accept my answer. – C. Peters May 29 '21 at 12:58
  • Accepted, thank you. Please also update the image of the results, since the document looks different with the \raggedright deleted. – Thomas VanDrunen May 29 '21 at 15:18