# Hide \thechapter for unnumbered Chapters

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.

EDIT: As an example, this is my code for the chapter. Using your solution – which works without an \if – I get the Error “\begin{document} missing“.

\titleformat{\chapter}[block]{\fontsize{40}{10}}{}{0em}{#1}[
\begin{textblock}{2}(13.7,3.2)
\color[rgb]{0.39453,0.48047,0.511719}   % Error Happens Here
\thechapter
\end{textblock}
]


As soon as I add a \if around the block, the error disappears.

\titleformat{\chapter}[block]{\fontsize{40}{10}}{}{0em}{#1}[
\iftrue{
\begin{textblock}{2}(13.7,3.2)
\color[rgb]{0.39453,0.48047,0.511719}   % No Error Happens with if
\thechapter
\end{textblock}
}
\fi
]

-
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? – jacob1123 Jun 29 '12 at 6:51
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

I would opt for a solution that is semantically more clear. titlesec provides the option to specify a different style for numberless sections.

Copy your original command, specify numberless, remove the things you don't want to show (like section numbers) and you're done!

\usepackage[explicit]{titlesec}
% Regular sections:
\titleformat{\section}[block]{\LARGE\selectfont}{}{0em}{}[\marginnote{\Huge\thesection}]
% ...etc

% Numberless sections:
\titleformat{name=\section,numberless}[block]{\LARGE\selectfont}{}{0em}{#1}
% ...etc

-
+1 for stealing my green tick:-) – David Carlisle Jun 24 '13 at 9:37
I just noticed a problem with your solution. As soon as I remove the \if...\fi around my definition (even \iftrue works), Latex gives me Missing \begin{document} at my \color{...} call. Any Ideas? @DavidCarlisle You might get it back, if I don't get this to work ;) – jacob1123 Jun 25 '13 at 7:32
@jacob11235 there is no color of \if in this solution or in your original question, so it isn't clear what code you are referring to that doesn't work? – David Carlisle Jun 25 '13 at 8:28
@DavidCarlisle I added the Code to the Question. The \if came from your answer. – jacob1123 Jun 25 '13 at 12:18
@DavidCarlisle Finally found the Problem. \color's optional argument's closing Bracket was matched to \titleformat's opening bracket. Adding braces around it fixed the Error. – jacob1123 Jul 2 '13 at 7:18

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.

-
Thanks! I'll vote up as soon as I reach 15rep ;) – jacob1123 Jun 29 '12 at 6:53