0

I'm trying to get a fancyhdr onto all pages of my appendix. The header and footer don't continue to the end of the section. There are different sections of the appendix (Appendix A, Appendix B, C, ...).

In the MWE, the fancyhdr stop after page 5. A MWE with my preamble is below. Should compile with pdflatex (maybe lualatex).

\documentclass[11pt,a4paper,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\usepackage[main=english,german]{babel} \usepackage{libertine} \usepackage{lettrine}

\makeatletter %% Define a HUGE font size \newcommand\HUGE{@setfontsize\Huge{35}{35}} \makeatother

\usepackage[doublespacing]{setspace} \usepackage{fancyhdr} \usepackage{booktabs} \usepackage{tabularx} \usepackage{float} \newcolumntype{Y}{>{\centering\arraybackslash}X} \usepackage{longtable} \usepackage{pgfplotstable} \newcommand{\sbx}[2][c]{% \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}} \usepackage{pdflscape} \usepackage{rotating} \usepackage{ragged2e} \usepackage{pdfpages} \usepackage[titletoc,title]{appendix}

\usepackage{titlesec}

\titleclass{\part}{top} % formatting part pages (https://tex.stackexchange.com/questions/431868/part-page-styling?rq=1) \titleformat{\part} [display] {\thispagestyle{empty}\raggedleft\fontfamily{LinuxBiolinumT-OsF}\selectfont\HUGE\bfseries} {\vspace{9cm}\MakeUppercase{\partname} \thepart} {0pt} {\vspace{10.5cm}\titlerule[.7pt]\vspace{.5cm}\Huge}

\titleclass{\chapter}{top} % formatting chapter pages (https://tex.stackexchange.com/questions/431868/part-page-styling?rq=1) \titleformat{\chapter} [display] {\raggedleft\fontfamily{LinuxBiolinumT-OsF}\selectfont\HUGE\bfseries} %{\vspace{-2cm}{}} {\vspace{1cm}{\chaptername} \thechapter} {0pt} {\vspace{1pc}\Huge} % \titlespacing*{\chapter}{0pt}{1.8cm}{1cm} %

\usepackage{afterpage} % command for blank pages \newcommand\blankpage{ \null \thispagestyle{empty} \addtocounter{page}{-1} \newpage }

\usepackage{emptypage} % additional package for blank pages

\usepackage{lipsum} \usepackage{filecontents}

%%%%%%%%%%%%%%%%%

\begin{document}

\begin{filecontents*}{data.csv}
    Number of points, Values
    10, 100
    20, 400
    30, 1200
    40, 2345
\end{filecontents*}


\renewcommand\chaptername{Appendix}     % change "chapter" header to "appendix

\newpage
\pagestyle{empty}
\part*{Appendix}    
\clearpage
\begin{appendices}
    \newpage
    \renewcommand\thefigure{A.\arabic{figure}} 
    \renewcommand\thetable{A.\arabic{table}} 
    \setcounter{table}{0}
    \setcounter{figure}{0}
    \pagestyle{fancy}
    \fancyhead{}
    \fancyhead[LE, RO]{\textbf{Appendix A}}
    \fancyfoot[C]{\thepage}
    \chapter*{Appendix A: My title} \label{app:A}
    \addcontentsline{toc}{chapter}{A: My title}

    \section*{My section 1}
    \lipsum[1]
    \subsection*{My subsection 1}
    \lipsum[2-4]
    \section*{My section 2}
    \begin{table*}[!htbp]
        \centering
        \caption{My table}
        \begin{footnotesize}
            \pgfplotstabletypeset[
            assign column name/.style={/pgfplots/table/column name={\textbf{#1}}},
            col sep=comma,
            column type=,
            begin table={\begin{tabularx}{.95\linewidth}{X c }},
                end table={\end{tabularx}},
            string type,
            columns/0/.style={string type,column name={}},
            columns/1/.style={string type,column name={}},
            every head row/.style={
                before row={\toprule\addlinespace},
                after row=\bottomrule\addlinespace},
            every last row/.style={after row=\bottomrule}
            ]{data.csv} 
        \end{footnotesize}
        \label{table}
    \end{table*}
    \subsection*{My subsection 1}
    \lipsum[2-4]
    \begin{table*}[!htbp]
        \centering
        \caption{My table}
        \begin{footnotesize}
            \pgfplotstabletypeset[
            assign column name/.style={/pgfplots/table/column name={\textbf{#1}}},
            col sep=comma,
            column type=,
            begin table={\begin{tabularx}{.95\linewidth}{X c }},
                end table={\end{tabularx}},
            string type,
            columns/0/.style={string type,column name={}},
            columns/1/.style={string type,column name={}},
            every head row/.style={
                before row={\toprule\addlinespace},
                after row=\bottomrule\addlinespace},
            every last row/.style={after row=\bottomrule}
            ]{data.csv} 
        \end{footnotesize}
        \label{table}
    \end{table*}
    \begin{table*}[!htbp]
        \centering
        \caption{My table}
        \begin{footnotesize}
            \pgfplotstabletypeset[
            assign column name/.style={/pgfplots/table/column name={\textbf{#1}}},
            col sep=comma,
            column type=,
            begin table={\begin{tabularx}{.95\linewidth}{X c }},
                end table={\end{tabularx}},
            string type,
            columns/0/.style={string type,column name={}},
            columns/1/.style={string type,column name={}},
            every head row/.style={
                before row={\toprule\addlinespace},
                after row=\bottomrule\addlinespace},
            every last row/.style={after row=\bottomrule}
            ]{data.csv} 
        \end{footnotesize}
        \label{table}
    \end{table*}
    \begin{table*}[!htbp]
        \centering
        \caption{My table}
        \begin{footnotesize}
            \pgfplotstabletypeset[
            assign column name/.style={/pgfplots/table/column name={\textbf{#1}}},
            col sep=comma,
            column type=,
            begin table={\begin{tabularx}{.95\linewidth}{X c }},
                end table={\end{tabularx}},
            string type,
            columns/0/.style={string type,column name={}},
            columns/1/.style={string type,column name={}},
            every head row/.style={
                before row={\toprule\addlinespace},
                after row=\bottomrule\addlinespace},
            every last row/.style={after row=\bottomrule}
            ]{data.csv} 
        \end{footnotesize}
        \label{table}
    \end{table*}
    \begin{table*}[!htbp]
        \centering
        \caption{My table}
        \begin{footnotesize}
            \pgfplotstabletypeset[
            assign column name/.style={/pgfplots/table/column name={\textbf{#1}}},
            col sep=comma,
            column type=,
            begin table={\begin{tabularx}{.95\linewidth}{X c }},
                end table={\end{tabularx}},
            string type,
            columns/0/.style={string type,column name={}},
            columns/1/.style={string type,column name={}},
            every head row/.style={
                before row={\toprule\addlinespace},
                after row=\bottomrule\addlinespace},
            every last row/.style={after row=\bottomrule}
            ]{data.csv} 
        \end{footnotesize}
        \label{table}
    \end{table*}
    \begin{table*}[!htbp]
        \centering
        \caption{My table}
        \begin{footnotesize}
            \pgfplotstabletypeset[
            assign column name/.style={/pgfplots/table/column name={\textbf{#1}}},
            col sep=comma,
            column type=,
            begin table={\begin{tabularx}{.95\linewidth}{X c }},
                end table={\end{tabularx}},
            string type,
            columns/0/.style={string type,column name={}},
            columns/1/.style={string type,column name={}},
            every head row/.style={
                before row={\toprule\addlinespace},
                after row=\bottomrule\addlinespace},
            every last row/.style={after row=\bottomrule}
            ]{data.csv} 
        \end{footnotesize}
        \label{table}
    \end{table*}
\end{appendices}

\afterpage{\blankpage}

\end{document}

SP1
  • 77
  • Please reduce your minimal working example (MWE) so that it only includes the necessary parts. Your code is way to long and does not even compile for me. – marv Jan 06 '22 at 21:21
  • @marv: I edited the code to make it shorter. Does it compile now? – SP1 Jan 06 '22 at 21:42
  • yes, the old code only compiled with pdflatex, not with lualatex. The new one compiles with both. But you should add the \documentclass back – marv Jan 06 '22 at 21:46
  • Sorry about that. Fixed. Any clever solutions? :) – SP1 Jan 06 '22 at 21:47
  • 1
    You should't hardcode the Appendix A in the header. LaTeX provides mechanism for that, such as \leftmark. However, this does not work with the starred commands such as \chapter*. Why are you not using the normal sectioning commands? – marv Jan 06 '22 at 21:59
  • I figured it out. Moving the lines from \pagestye{fancy} up to \fancyfoot before \begin{appendices fixes your problem. – marv Jan 06 '22 at 22:03
  • I need all of that after \begin{appendices} because I have different appendices (Appendix A, B, C, D, E), and that code changes the header for each appendix "chapter"...I'm getting the feeling that I should be doing this differently, but I don't know how. – SP1 Jan 06 '22 at 22:12
  • So I moved \pagestye{fancy} before \begin{appendices}, and now there's a header on the remaining pages, but it's the wrong one (it's from the "References" section above (not in the MWE)). – SP1 Jan 06 '22 at 22:22

1 Answers1

1

The problem with your \pagestyle definitions inside the appendices environment is that these definitions are local to the environment. When the environment finishes the definition that was active outside the environment is restored. In your case that is \pagestyle{empty}.

There are two ways to solve this:

  1. Put the definition before the appendices environment. As you noted this only will work if you have a definition that works for multiple appendices. This can be done if you use \leftmark instead of the appendix title in \fancyhead.
  2. Add a \clearpage before \end{appendices}. This causes all pages to be generated with the proper headers, before the header definitions are reset. Adding a \clearpage is a good idea anyhow, because it flushes all pending figures and tables in the appendices section.

And after the \clearpage, you can just use \blankpage. No need for \afterpage`.

By the way, I don't think you really use the functionality of the appendices environment, so you could probably get rid of it.

To have complete control of your headers and table of contents for the appendices, you can use \chapter* as you have noted, but then you have to add \markboth yourself for the headers. Also you have to increment the chapter (=appendix) number yourself. The best way is to define a macro that does the work.

So here is the solution:

\newcommand{\Achapter}[1]{%
  \refstepcounter{chapter}
  \chapter*{\appendixname\ \thechapter: #1}
  \markboth{\appendixname\ \thechapter}{}
  \addcontentsline{toc}{chapter}{\thechapter: #1}
}
. . .
        \pagestyle{fancy}
        \setlength{\headheight}{14pt}
        \fancyhead{}
        \fancyhead[LE, RO]{\textbf{\leftmark}}
        \fancyfoot[C]{\thepage}
        % \chapter*{Appendix A: My title} \label{app:A}
        % \addcontentsline{toc}{chapter}{A: My title}
        \Achapter{My Title}
. . .
        \clearpage
    \end{appendices}
    \blankpage