4

Having a problem somewhat akin to "How to put section number into the right side of section title in LaTeX" (and neither of the two answers there floating my boat), I was tinkering with titlesec, and came across an error message I cannot fathom.

Ignoring good looks of the example for the sake of brevity, this works:

\documentclass{scrbook}
\usepackage[german]{babel}
\usepackage[utf8]{inputenc}

\usepackage{titlesec}
\titleformat{\section}[hang]{}{\thesection}{0pt}{}{}   %% <--

\begin{document}
\section{Section}
\end{document}

(Yields "0.1Section".)

Switching the marked line to this also works:

\titleformat{\section}[hang]{}{}{0pt}{\thesection}{}

(Yields "0.1Section".)

However, the following line does not work:

\titleformat{\section}[hang]{}{}{0pt}{}{\thesection}

(Expected "Section0.1", but yields LaTeX Error, "Missing \begin{document}".)

Apparently the "after"-Field of \titleformat handles things differently. Why does this happen, and can it be avoided?

0

1 Answer 1

8

The "after" field is optionally specified in square brackets after the "before" field, not in curly braces. This is why this fails.

The proper syntax is thus:

\titleformat{\section}[hang]{}{}{0pt}{}[\thesection]

which yields the expected result:

Section

0.1

1
  • /doublefacepalm...
    – DevSolar
    Aug 9, 2011 at 13:44

You must log in to answer this question.

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