TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With the following MWE, i get the Section title underlined in black :


{Section \arabic{section}}%

\section{mon titre}

My first problem : if i remove the { } enclosing \titlerule, i get a compilation error

! LaTeX Error: Missing \begin{document}

Which is strange, since the content of the [ ] is a text to typeset after the section title. For example


works. My second problem : if i colorize the rule with


I obtain a blue underline, but with an additional vertical space (app 0.5 cm) between the title and the underline. If i use


instead, the vertical space disappears... I have to admit, i do not understand that.

share|improve this question
To see why \textcolor starts a new paragraph (mentioned in @egreg's answer), add \makeatletter\show\@textcolor\makeatother after \titleformat, then inspect your .log file and see that it executes \leavevmode (\@textcolor is just a subsidiary function called by \textcolor). Then read Function and usage of \leavevmode. – Werner Jan 4 '12 at 22:01
thanks for the information ! – nicolas roy Jan 5 '12 at 7:41
up vote 10 down vote accepted

It's not strange: without the braces, in the first case, the first closing ] is matched with the opening [ that announces the optional argument to \titleformat. An optional argument always goes from the [ to the first ] (at the same brace level).

The second problem is due to the fact that \textcolor starts a paragraph, while \color doesn't. But, as you already discovered, using \color inserts a break point and the rule may go on the following page.


  {Section \arabic{section}}
share|improve this answer
thanks a lot for all the information ! – nicolas roy Jan 5 '12 at 7:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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