# Why is the appendix title not inserted to the header in twopage documents?

I'm writing my thesis in the twoside article class and wondered why the title of the appendices wasn't inserted into the fancyhdr. After a bit of error searching, I finally found the problem. It's caused by the twoside option. In a one sided document, the title is inserted, in a two sided document it isn't.

Why is that, and how could I fix it?

### Edit

With \pagestyle{fancy} the title is also inserted in the header.

## MWE

\documentclass[11pt, twoside]{article}

% %%%%%%%%
% Preamble
% %%%%%%%%

\usepackage[english]{babel}
\usepackage[T1]{fontenc}

\usepackage{%
geometry,%
fancyhdr,%
lipsum%
}

\geometry{%
a4paper,%
top=3cm,%
bottom=3.5cm,%
outer=2.5cm,%
inner=3.5cm,%
nomarginpar,%
showframe=false%
}

\fancypagestyle{general}{%
\fancyhf{}                  % Clean fields
\fancyfoot[R]{\thepage}
\renewcommand{\footrulewidth}{0.4pt}
}

% %%%%%%%%%%%%%%%%%%
% Begin the document
% %%%%%%%%%%%%%%%%%%

\begin{document}

\pagestyle{general}

\section{Section}
\lipsum

\newpage
\begin{appendices}
\section{Foo bar}
\lipsum[1-2]
\end{appendices}

\end{document}


Oh and by the way: Does anybody know how I could add a colon (:) between Appendix A and Foo bar, making the title Appendix A: Foo bar instead of Appendix A Foo bar?

Edit: The real 'culprit' is the change of \sectionmark in appendices, see the 2nd solution below.

Two-side setups require specification of LE,RO and LO,RE, i.e. left even, right odd and left odd,right even settings for \fancyhead etc.

Using \fancyhead[R] isn't enough since \rightmark has a different meaning in twoside option.

Also, don't use \usepackage{geometry,fancyhdr} in a row, use one line per package, otherwise you can't specify options to one package that are not known by another one.

Add headheight=20pt for example to prevent the warning by fancyhdr.

\documentclass[11pt, twoside]{article}

% %%%%%%%%
% Preamble
% %%%%%%%%

\usepackage[english]{babel}
\usepackage[T1]{fontenc}

\usepackage{geometry}

\geometry{%
a4paper,%
top=3cm,%
bottom=3.5cm,%
outer=2.5cm,%
inner=3.5cm,%
nomarginpar,%
showframe=false%
}

\usepackage{fancyhdr}
\usepackage{lipsum}

\usepackage{xpatch}

\fancypagestyle{general}{%
\fancyhf{}                  % Clean fields
\fancyfoot[R]{\thepage}
\renewcommand{\footrulewidth}{0.4pt}
}

% %%%%%%%%%%%%%%%%%%
% Begin the document
% %%%%%%%%%%%%%%%%%%

\begin{document}
\pagestyle{general}

\section{Section}
\lipsum

\clearpage

\begin{appendices}
\section{Foo bar}
\lipsum[1-10]
\end{appendices}

\end{document}


Using an new version of appendices, by changing the \sectionmark macro that is redefined in appendices from appendix code already:

\documentclass[11pt, twoside]{article}

% %%%%%%%%
% Preamble
% %%%%%%%%

\usepackage[english]{babel}
\usepackage[T1]{fontenc}

\usepackage{geometry}

\geometry{%
a4paper,%
top=3cm,%
bottom=3.5cm,%
outer=2.5cm,%
inner=3.5cm,%
nomarginpar,%
showframe=false%
}

\usepackage{fancyhdr}
\usepackage{lipsum}

\usepackage{xpatch}

\fancypagestyle{general}{%
\fancyhf{}                  % Clean fields
\fancyfoot[R]{\thepage}
\renewcommand{\footrulewidth}{0.4pt}
}

\makeatletter

\renewenvironment{appendices}{%
\@resets@pp
\if@dotoc@pp
\if@dopage@pp              % both page and toc
\if@chapter@pp           % chapters
\clear@ppage
\fi
\appendixpage
\else                      % toc only
\if@chapter@pp          % chapters
\clear@ppage
\fi
\fi
\else
\if@dopage@pp              % page only
\appendixpage
\fi
\fi
\if@chapter@pp
\if@dotitletoc@pp \@redotocentry@pp{chapter} \fi
\else
\if@dotitletoc@pp \@redotocentry@pp{section} \fi
\def\sectionmark##1{%
\if@twoside
\markright{\@formatsecmark@pp{##1}}
\else
\markright{\@formatsecmark@pp{##1}}{}
\fi}
\fi
\if@dotitle@pp
\def\sectionname{\appendixname}
\def\@seccntformat##1{\@ifundefined{##1name}{}{\csname ##1name\endcsname\ }%
\fi
\fi}{%
\@ppsaveapp\@pprestoresec}
\makeatother

% %%%%%%%%%%%%%%%%%%
% Begin the document
% %%%%%%%%%%%%%%%%%%

\begin{document}
\pagestyle{general}

\section{Section}
\lipsum

\clearpage

\begin{appendices}
\section{Foo bar}
\lipsum[1-10]
\end{appendices}

\end{document}

• This does only work with \leftmark. I however don't use \leftmark but only \rightmark :/ Is there a way to still get it working? – Sam Feb 25 '18 at 23:33
• @Sam: I've provided a second solution, but in my point of view, you're misusing \rightmark here – user31729 Feb 25 '18 at 23:46
• Thank you! I went for a more simple solution than your redefinition. I created a second pagestyle named appendix and added it to the hook called with \begin{appendices}. – Sam Feb 26 '18 at 0:02
• @Sam: That's what I have done in my version zero (not shown here) but I was unsatisfied with it... – user31729 Feb 26 '18 at 0:03
• Any specific reason? – Sam Feb 26 '18 at 0:03