1

I am trying to turn off hyphenation in the table of contents. Here is a minimal working example with my titletoc setup:

\documentclass[a5paper]{article}
\usepackage[italian]{babel}
\usepackage{titletoc}

\contentsmargin{4em}
\titlecontents{section}
   [15mm] % ie, 1.5em (chapter) + 2.3em
   {}
   {\hspace*{-5mm}\parbox[t][]{5mm}{\textbf{\thecontentslabel.}}}
   {\hspace*{-5mm}\parbox[t][]{5mm}{\textcolor{gray}{$\blacksquare$}}}
   {\titlerule*[1pc]{ }{\sffamily\bfseries\contentspage}}

\begin{document}

\tableofcontents

\section{Eterogeneità dei rischi, assicurazione e soluzioni di mercato}

\end{document}

The result I obtain is what I want, except for the hyphenation in the table of contents ("Indice").

enter image description here

I tried a number of solutions to get rid of hyphenation, such as adding \hyphenpenalty 1000 or \raggedright to the <above-code> and at the end of the <numbered-entry-format> arguments of \titlecontents, but the only result was to mess up alignment.

8
  • 1
    As always here you are much more likely to get help if you provide a full but minimal example others can copy and test as is. That said add \raggedright to your parboxes and remember that \sf has been deprecated since 1993! use \sffamily
    – daleif
    Dec 4, 2022 at 12:12
  • But parboxes are for the label, aren't they? In fact, I added \raggedright inside parboxes and there was no effect on the text
    – Massimo
    Dec 4, 2022 at 12:16
  • I never use titletoc so unfamiliar with the syntax. Provide a full but minimal example, then we'll see if someone who knows titletoc can help. BTW: titletoc has a manual, search for ragged.
    – daleif
    Dec 4, 2022 at 12:47
  • I know it has a manual ;-)
    – Massimo
    Dec 4, 2022 at 12:56
  • I can't reproduce the output: with babel there's no hyphenation; without it, I get hyphenation both in the TOC and in the section title.
    – egreg
    Dec 4, 2022 at 13:44

1 Answer 1

1

Add \filright in the appropriate argument. I also suggest to use a zero width box for the section number.

\documentclass[a5paper]{article}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage{titletoc}

\contentsmargin{3em}
\titlecontents{section}
   [15mm] % ie, 1.5em (chapter) + 2.3em
   {\filright}
   {\makebox[0pt][r]{\bfseries\thecontentslabel.\@ }}
   {\makebox[0pt][r]{\textcolor{gray}{$\blacksquare$ }}}
   {\titlerule*[1pc]{ }{\sffamily\bfseries\contentspage}}

\begin{document}

\tableofcontents

\section{Eterogeneità dei rischi, assicurazione e soluzioni di mercato}

\setcounter{section}{9}

\section{Eterogeneità dei rischi, assicurazione e soluzioni di mercato}

\end{document}

enter image description here

For avoiding hyphenation in the section titles, modify them with \titleformat from titlesec.

You must log in to answer this question.

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