I would like to redefine the \section and \section* to produce section titles that look roughly like this: illustration of desired section title formatting that is, text in white over a black bar that extends from left to right margin. I don't anticipate any section titles being longer than one line.


1 Answer 1


Here's one possible solution using the explicit option for the titlesec package:




\section{A Test Section}
\section{Another Test Section}
\section{Another Test Section with a long title spanning more than one line}
\section*{An Unnumbered Test Section}


The idea is to use a \parbox of width equal to \textwidth (-2\fboxsep) inside a black \colorbox; inside this \colorbox the text is set to white using \textcolor.

enter image description here

  • This solution does not exhibit the expected behavior with \section* (it correctly does not increment thesection, but it still displays it). It also adds a lot of undesirable extra vertical space above and below the section title. Commented Jun 7, 2012 at 2:36
  • Hadn't seen your edit yet. First objection retracted. Second still stands. Commented Jun 7, 2012 at 2:37
  • @thecommexokid see my updated answer. Is that what you want? Commented Jun 7, 2012 at 2:39
  • Is very nice now, yes. Could you explain what all the parts are doing? Commented Jun 7, 2012 at 2:41
  • 4
    @thecommexokid I've added a brief explanation; \titleformat is explained in the documentation of titlesec. Commented Jun 7, 2012 at 2:45

You must log in to answer this question.

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