# Current situation

My document (report) consists of chapters, sections and subsections. Now I want to display the section name and the subsection name on the left side of the footer. However if I use \rightmark I only get the section name, not the subsection one too.

# A minimal example

I tried to reduce the problem to this minimal example which is basically the code from my actual document:

\documentclass[a4paper,12pt]{report}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

% ...
% a lot of other stuff here
% ...

% <toc>
\setcounter{secnumdepth}{0}

\newcommand\invisiblesection[1]{%
\refstepcounter{section}%
\sectionmark{#1}}

\newcommand\invisiblesubsection[1]{%
\refstepcounter{subsection}%
\subsectionmark{#1}}
% </toc>

\begin{document}
\tableofcontents
\newpage

\chapter{a chapter}
\newpage

\invisiblesection{section}
\invisiblesubsection{subsection}
content to ensure the page is there
\newpage

\invisiblesection{another section}
\invisiblesubsection{subsection 1}
content to ensure the page is there
% the header should now display "another section - subsection 1"
\newpage

\invisiblesubsection{subsection 2}
content to ensure the page is there
% the header should now display "another section - subsection 2"
\newpage

\invisiblesubsection{subsection 3}
content to ensure the page is there
% the header should now display "another section - subsection 3"
\end{document}


# What I tried so far

• overriding both marks - didn't work as the \leftmark was defined as the chapter's name
• getting the current section name with nameref - didn't work as it was fetching the chapter's name
• \defining custom variables each time a \invisiblesection is created - didn't work either

# Question

I suppose there's just one dead simple flag which I forgot but google didn't tell me. Does anybody have a solution to display both the section and subsection name in a header/footer?

• The default definition of \subsectionmark is “do nothing”. – egreg Jan 5 '16 at 21:23
• Some more details are needed: do you always have a subsection starting after a section title? If not, what should the header display? – egreg Jan 5 '16 at 21:28
• How would I go about appending something to the \rightmark then? I've read that only the first occurence of of it will be used. I updated the question to show how it's in the actual document. – michaeln Jan 5 '16 at 21:31
• Edited the code and added what it should look like. – michaeln Jan 5 '16 at 21:33
• The addition is quite unclear; you can typically have only the first subsection that starts in the current page in the header. Do you need chapter titles in the header or footer? – egreg Jan 5 '16 at 21:36

The \subsectionmark command is defined to do nothing, so you need to change its definition if you want it issues a mark.

Similarly, you have to change \sectionmark so it doesn't issue a mark.

\documentclass[a4paper,12pt]{report}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\setcounter{secnumdepth}{0}

\newcommand\invisiblesection[1]{%
\refstepcounter{section}%
\sectionmark{#1}%
}

\newcommand\invisiblesubsection[1]{%
\refstepcounter{subsection}%
\subsectionmark{#1}%
}

\renewcommand{\sectionmark}[1]{%
\gdef\currsection{#1}%
}
\renewcommand{\subsectionmark}[1]{%
\markright{\currsection\ \textbullet\ #1}%
}

\begin{document}

\tableofcontents
\newpage

\invisiblesection{section}
\invisiblesubsection{subsection}
content to ensure the page is there
\newpage

\invisiblesection{another section}
\invisiblesubsection{subsection 1}
content to ensure the page is there
% the header should now display "another section - subsection 1"
\newpage

\invisiblesubsection{subsection 2}
content to ensure the page is there
% the header should now display "another section - subsection 2"
\newpage

\invisiblesubsection{subsection 3}
content to ensure the page is there
% the header should now display "another section - subsection 3"

\end{document}


Here's the top of page 4