0

Following up this question of mine (Increase margin in section titles with titlesec), I'd like to configure my Table of Contents in a similar way, mainly to substitute the bold font for section titles with a slightly larger font and to remove the dotted lines. MWE:

\documentclass{article}
\usepackage{titletoc}
\titlecontents{section}
[0pt]
{}
{\Large\thecontentslabel\enspace}
{}
{\hfill\contentspage}                 
[]
\begin{document}
\tableofcontents
\section{This is another long long long long long long section name}
\end{document}

The goal is to get in the ToC:

1. This is another long long long long
long long section name

instead of:

1. This is another long long long long long long sec-
tion name

So no hyphenation and a specified length. This is to prevent something like this in my document. The package documentation is not very clear to me. The command \contentsmargin{2.5cm} does indeed manipulate the right margin in the way I need it but it leads to some misplaced page numbers too.

5
  • Please post a small complete code that illustrates your problem.
    – Bernard
    Jul 24 '21 at 18:00
  • I use LyX and it is hard to reproduce. One section title is just long enough to reach the right margin without a line break so that the page number follows it on the next line but on the left hand side. I also copied the code above from another answer and don't really understand the syntax of titletoc. As said, I want to substitute the bold font of section titles with a larger font and to remove the dotted lines.
    – johnny7
    Jul 24 '21 at 18:22
  • Can't make with Lyx a small fake document and post the resulting code?
    – Bernard
    Jul 24 '21 at 18:27
  • I edited my question with a MWE. Some general remarks about the differences between dottedcontents, titlecontents and contentsmargin would be greatly appreciated!
    – johnny7
    Jul 24 '21 at 18:38
  • Answer updated after your edit. No hyphenation and adjustable title width. Jul 24 '21 at 21:42
0

UPDATE no hyphenation plus a narrow section title by adjusting its left and right "margins".

z

\documentclass{article}

\usepackage{titletoc}   

\titlecontents{section}%
[0mm]% 
{\Large\raggedright}% no hyphenation
{\contentspush{\makebox[75mm][l]{\thecontentslabel.} \hspace{-45mm}}}% use the makebox width and the \hspace to set the title
{}%
{\contentsmargin{25mm}\hfill\contentspage}%
[\vspace{3ex}]

\begin{document}
    \tableofcontents
    \newpage
    \section{As any dedicated reader can clearly see, the Ideal of
        practical reason is a representation of the things
        in themselves.}
    \section{IntroductionIntroduction IntroductionIntroductionI}
\end{document}

f

Try this code.

\documentclass{article}

\usepackage{titletoc}

\titlecontents{section}% <section-type>
[2.3em]%  align left
{\Large}% <above-code> Larger font <<<<<<<<<<<
{\hspace*{-1.5em}\makebox[1.5em][l]{\thecontentslabel.}}% <numbered-entry-format>
{}% <numberless-entry-format>
{\hfill\contentspage}% <filler+ page-format>
[\vspace{2ex}]  

\begin{document}
    \tableofcontents
    \newpage
    \section{As any dedicated reader can clearly see, the Ideal of
        practical reason is a representation of the things
        in themselves.}
    \section{IntroductionIntroduction IntroductionIntroductionI}
\end{document}
13
  • Thank you! Unfortunately, one page number is still on the left side. I added a graphic above. What does the 1.5em indicate in your code?
    – johnny7
    Jul 24 '21 at 19:13
  • @johnny7 Which number? Jul 24 '21 at 19:17
  • @johnny7 [1.5em] is the indent used in book . Change the value and see what happens. Jul 24 '21 at 19:18
  • With a specific length of a chapter name, the page number still appears left as in the image I added in my question, no matter whether I use the makebox.
    – johnny7
    Jul 24 '21 at 19:35
  • @johnny7 Are you able to compile my code, as it is? Jul 24 '21 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.