Take the 2-minute tour ×
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.

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?

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

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

share|improve this answer
    
/doublefacepalm... –  DevSolar Aug 9 '11 at 13:44
add comment

Your Answer

 
discard

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.