fancyhdr 没有显示在附录的所有页面上

fancyhdr 没有显示在附录的所有页面上

我正在尝试将 fancyhdr 放到附录的所有页面上。页眉和页脚没有延伸到该部分的末尾。附录有不同的部分(附录 A、附录 B、C,...)。

在 MWE 中,fancyhdr 在第 5 页后停止。下面是带有我的序言的 MWE。应该使用 pdflatex(可能是 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}

答案1

\pagestyle环境内部定义的问题appendices是这些定义是环境本地的。当环境完成时,环境外部活动的定义将被恢复。在你的情况下是\pagestyle{empty}

有两种方法可以解决这个问题:

  1. 将定义放在环境之前。正如您所指出的,只有当您有一个适用于多个附录的定义时,这才会起作用。如果您使用而不是附录标题,appendices则可以做到这一点。\leftmark\fancyhead
  2. \clearpage在之前添加\end{appendices}。这会导致在重置标题定义之前,生成所有带有正确标题的页面。\clearpage无论如何,添加 都是一个好主意,因为它会刷新附录部分中所有待处理的图表和表格。

并且在\clearpage, you can just use\blankpage . No need for\afterpage` 之后。

顺便说一句,我认为您并没有真正使用环境的功能appendices,因此您可能应该摆脱它。

要完全控制附录的标题和目录,您可以使用\chapter*您已注意到的方法,但您必须\markboth自己添加标题。您还必须自己增加章节(=附录)编号。最好的方法是定义一个可以完成这项工作的宏。

解决方案如下:

\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

相关内容