2

let me preface this with saying I don't fully understand fancyhdr. I am trying to achieve getting the same header on every page: the left top showing the chapter number, section number and section title -- and the right top the page number. I.e.

  • 1.1 section title
  • 1.3 next section
  • 2.1 new chapter
  • bibliography (can manually switch styles for this)
  • A.1 appendix section
  • A.2 another appendix section

I can get this to work just fine in the normal chapters, but the approach fails when I use the 'appendix' package (which I use to achieve getting the 'appendix' entry in the TOC). A minimal example:

\documentclass[a4paper]{report}
\usepackage[utf8]{inputenc}

% Include appendix
\usepackage[titletoc]{appendix}

% Fancyhdr
\usepackage{fancyhdr}
% Custom style:
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhead[L]{\thesection. \rightmark}
\fancyhead[R]{\thepage}
\fancyfoot{}

\begin{document}

\tableofcontents

\chapter{The Ghost Problem}
\section{Bill murray}
Test
\newpage
\section{blockbusters}

% ============================================================================
% = APPENDICES ===============================================================
% ============================================================================

\clearpage
\begin{appendices}
\chapter{Other disasters}
    \section{Godzilla}
    \newpage
    \section{Mordor}
    \newpage
    \section{Darth vader}
\end{appendices}

\end{document}

If you compile this file, you'll find that the last page will show 1.3 rather than A.3 in the header, basically falling back to the last know \leftmark information or so..?

If I use \appendix instead, this issue is not present. Any hints?

  • A warm welcome to TeX.SE! Excellent first question with a good, compilable, MWE. – A Feldman Jun 24 '16 at 14:39
2

Just comment the renewcommand line and change \fancyhead[L] to something simpler.

% \renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhead[L]{\rightmark}
  • 1
    Good, that fixes the numbering issue! I wrapped it in \nouppercase{\rightmark} to remove the smallcaps. Seems to work, thanks a lot! :-) – Erik Jun 24 '16 at 14:49

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.