The following (other than the \setcounter{secnumdepth}{0}) is taken from User math's answer in Underline the section title text in table of contents.

% The line below seems to be incompatible with the underlining of the line beneath it
% \setcounter{secnumdepth}{0}

If one un-comments the commented line of code, one can not have both \setcounter{secnumdepth}{0}, and have the underlining working at the same time.

I wonder why, and whether there is a way to circumvent this, without resorting to the soulpackage (as had done User math in his answer; and others; in the mentioned OP), thus by still using the 2 currently incompatible lines up to a great extent at least.


There is no incompatibility, only errors in the syntax for \titlecontents.

The first argument is for code preceding the section label. Furthermore, there an optional-mandatory argument, which is the distance form the left margin. Also, don't use \underline here: you might have long titles, and \underline does not break across lines. Use \ul from soul(utf8) instead.


However, there is an incompatibility if using `hyperref. I added a hack, due to Heiko Oberbiek, to circumvent the problem.

\usepackage[utf8]{inputenc} \usepackage{titletoc}
\usepackage{soulutf8} % The line below seems to be incompatible with the underlining of the line beneath it




\section{Foobar. A quite long, long section title. A still longer, longer, longer subsection title}
Some test.

\section{Another, shorter, section}
Some more text.


enter image description here

  • Thanks! This answer is incompatible with \usepackage{hyperref} though...
    – O0123
    May 25 '16 at 6:21
  • Could you explain in what way it is incompatible?
    – Bernard
    May 25 '16 at 9:22
  • If you add that line (\usepackage{hyperref}) in your MWE, then it is no longer compilable (I'm on Texshop, using LaTeX as a Program, where it still compiles once, but not twice and more). I get the following error, from the .toc: \hyper@linkstart has an extra }.
    – O0123
    May 25 '16 at 9:25
  • @Vincent Verheyen: Problem solved (Heiko Oberdiek's hack)! Please take a look at my updated answer.
    – Bernard
    May 25 '16 at 10:09

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.