0

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%
}

\usepackage[titletoc, title, header]{appendix}

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

\fancypagestyle{general}{%
    \fancyhf{}                  % Clean fields
    \fancyhead[R]{\itshape\nouppercase{\rightmark}}
    \renewcommand{\headrulewidth}{0.4pt}
    \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?

2

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{%
  headheight=20pt,
    a4paper,%
    top=3cm,%
    bottom=3.5cm,%
    outer=2.5cm,%
    inner=3.5cm,%
    nomarginpar,%
    showframe=false%
}


\usepackage{fancyhdr}
\usepackage{lipsum}

\usepackage{xpatch}
\usepackage[titletoc, title,header]{appendix}


\fancypagestyle{general}{%
  \fancyhf{}                  % Clean fields
  \fancyhead[LE,RO]{\itshape\nouppercase{\rightmark}}
  \fancyhead[LO,RE]{\itshape\nouppercase{\leftmark}}
  \renewcommand{\headrulewidth}{0.4pt}
  \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{%
  headheight=20pt,
    a4paper,%
    top=3cm,%
    bottom=3.5cm,%
    outer=2.5cm,%
    inner=3.5cm,%
    nomarginpar,%
    showframe=false%
}


\usepackage{fancyhdr}
\usepackage{lipsum}

\usepackage{xpatch}
\usepackage[titletoc, title,header]{appendix}


\fancypagestyle{general}{%
  \fancyhf{}                  % Clean fields
  \fancyhead[R]{\itshape\nouppercase{\rightmark}}
  \renewcommand{\headrulewidth}{0.4pt}
  \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
      \addappheadtotoc
    \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
    \if@dohead@pp
      \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\ }%
        \csname the##1\endcsname\ifnum0=\pdfstrcmp{##1}{section}:\fi\quad}
    \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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.