Tell me more ×
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.

I want to display my Chapter-Numbers on the right below the Title. I came to the following minimal working example:

\documentclass{article}
\usepackage{titlesec}
\usepackage{marginnote}
\usepackage{lipsum} % for dummy text only
\titleformat{\section}[block]{\LARGE\selectfont}{}{0em}{}[\marginnote{\Huge\thesection}]

\begin{document}
    \section{First section with\\linebreak}
        \lipsum[2]
    \section*{Unnumbered}
        \lipsum[12]
    \section{Three}
        \lipsum[5]
\end{document}

However the unnumbered section now gets numbered as 1. How can I suppress \thesection for unnumbered sections? When I move the \marginnote to the <label> field in \titleformat the Number 'ignores' that the Title contains linebreaks and is positioned relative to the first line.

share|improve this question
I think I would use \llap instead of \marginnote – cmhughes Jun 28 '12 at 17:37
@cmhughes Could you give an example of using \llap instead of \marginnote? Why would you use it instead? – jacob11235 Jun 29 '12 at 6:51
1  
I just compiled your MWE- nevermind, I see that \llap wouldn't produce the same results, my mistake – cmhughes Jun 29 '12 at 15:13

1 Answer

up vote 7 down vote accepted

You can test whether the * version is being used by

\makeatletter
\titleformat{\section}[block]{\LARGE\selectfont}{}{0em}{}[\if\ttl@key@numberless\marginnote{\Huge\thesection}\fi]
\makeatother

as \ttl@key@numberless is // for numbered form so the \if is true as the same character appears twice, and it is /* for the unnumbered section so the \if compares / and * which are false.

share|improve this answer
Thanks! I'll vote up as soon as I reach 15rep ;) – jacob11235 Jun 29 '12 at 6:53

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.