I need to typeset the table of contents entries ragged right (instead of being justified):
1.2.2 Short title . . . . . 42
1.2.3 Long section title
can be wrapped . . . . 44
1.2.4 Another short title . 45
I have already asked a similar question and got excellent answers. There is also another similar question regarding the memoirpackage.
However, this time I have to use the titletoc package (together with the standard book class), and the current answers do not seem to be compatible with it.
As a simple example, here is a definition of how to typeset section headings:
\contentsmargin{7mm}
\titlecontents{section}
[15mm]
{}
{\contentslabel{9mm}}
{\hspace*{-9mm}}
{\titlerule*[1pc]{.}\contentspage}
How can I tweak the definition so that the section headings are ragged right (but otherwise the typesetting is just like what I have now)?
Edit: Full MWE:
\documentclass[oneside,12pt,a4paper]{book}
\usepackage{titletoc}
\newcommand{\foo}{Loremipsum dolorsitamet, consectetueradipiscingelit. Utpuruselit, vestibulumut, placeratac, adipiscingvitae, felis. Curabiturdictum gravidamauris. Namarculibero, nonummyeget, consectetuerid, vulputatea, magna. Donecvehicula augueeuneque.}
\contentsmargin{7mm}
\titlecontents{chapter}
[6mm]
{\addvspace{4mm}\bfseries}
{\contentslabel{6mm}}
{\hspace*{-6mm}}
{\titlerule[0pt]\contentspage}
[\addvspace{2mm}]
\titlecontents{section}
[15mm]
{}
{\contentslabel{9mm}}
{\hspace*{-9mm}}
{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}
[27mm]
{}
{\contentslabel{12mm}}
{\hspace*{-12mm}}
{\titlerule*[1pc]{.}\contentspage}
\begin{document}
\tableofcontents
\chapter{\foo}
\section{\foo}
\subsection{\foo}
\end{document}
And here is a rough approximation of what kind of output I am expecting (ragged right, no hyphenation):

This was achieved with tocstyle, as suggested in this answer. However, it is not compatible with titletoc, and I need to use titletoc to control other aspects of the layout (margins, spacing, fonts, colours, etc.).


\raggedrightitself, which makes something I don't understand with the layout of the table of contents. A work around is to make\hyphenpenalty = 10000to suppress locally all hyphenation. – Bernard Sep 21 '14 at 12:42\hyphenpenaltyis still trying to make everything fully justified; you just get lots of overfull hboxes, so it "looks ragged". However, if you happen to have short enough words in the section titles, you will see that Latex is still stretching inter-word spacing to make the text as much fully justified as possible. – Jukka Suomela Sep 21 '14 at 12:51\overfullrule=1mmand pay attention to the lines that are not marked with the overfull marker.) – Jukka Suomela Sep 21 '14 at 12:53\section{Lorem ipsum}before\section{\foo{}}in your example. Then you will see that the spacing between "Lorem" and "ipsum" in 1.1 is different from the spacing in 1.2 right below it.) – Jukka Suomela Sep 21 '14 at 12:58