I have the same problem as How to use short subsection title in header but not in table of contents?, and the solution given works almost well.
The difference is that also use the package titlesec
. Here the code
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{titlesec}
\pagestyle{fancy}
\newcommand{\markedsection}[2]{\section[#2]{#2%
\sectionmark{#1}}
\sectionmark{#1}}
\newcommand{\markedsubsection}[2]{\subsection[#2]{#2%
\subsectionmark{#1}}
\subsectionmark{#1}}
\lhead{\nouppercase \leftmark} \chead{} \rhead{\nouppercase \rightmark}
\begin{document}
\thispagestyle{plain}
\tableofcontents
\markedsection{short section}{Some section with quite a lengthy title}
\lipsum
\markedsubsection{short subsection}{Very very very long title of subsection}
\lipsum
\end{document}
But on the page where the subsection appears for the first time, the title in the header has not been modified, it is still the original long title, whereas on the next pages, the subsection titles ih the header is the short one. I want of course the short one even the first time. If I remove the titlesec package, everything works fine, as on the other post.
Can anyone help me with that ?
Best Answer
I don't know how to tackle the problem with
fancyhdr
, but since you usetitlesec
, I suggest doing it with thetitleps
module oftitlesec
instead. For unnumbered subsections, I had to define a new command (nonumsubsection
) becausetitlesec
doesn't seem to manage the formatting of starred (sub)sections with an optional argument :