如何在多个页面上应用不同的 fancyhdr 页面样式

如何在多个页面上应用不同的 fancyhdr 页面样式

我有以下文件结构:

my_doc
├── Pages
│   ├── blankPage.tex
│   ├── Page1.tex
│   └── Page2.tex
├── customPreamble.sty
└── main_file.tex

我已将所有\usepackage{}调用都放在文件中.sty。问题如下:

我已经定义了\fancypagestyle{}三个自定义序言.sty文件。在主文件.tex我首先使用\pagestyle{empty}通话。然后我包括第1页.tex第2页通过\input{]电话。

在每个页面中,我在页面顶部定义了:

\pagestyle{stylename}

现在,编译过程xelatex运行正常,没有任何明显错误,但页面样式尚未完全应用

如何解决这个问题?

所有文件附于下方:

自定义序言.sty

\usepackage[outer=0.6in,headheight=77pt,top=3cm, bottom=2.5cm]{geometry}
\usepackage{listings}
\usepackage{underscore}
\usepackage[]{hyperref}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{color, colortbl}
\usepackage[many]{tcolorbox}
\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0pt}%{0.75pt}
\definecolor{headerYellow}{rgb}{0.96, 0.78, 0.36}
\definecolor{greyShade}{RGB}{0,20,20} % Color of the boxes behind the abstract and headings

\usepackage{titlesec}

\titleformat{\chapter}
{
    \Large% %change this size to your needs for the first line
    \bfseries}{\chaptertitlename\ \thechapter}{14pt}{%
    \Large %change this size to your needs for the second line
}
\titleformat*{\section}{\large\headingfont} 

\hypersetup{
    %bookmarks=true,    % show bookmarks bar?
    pdftitle={blah},    % title
    pdfauthor={blah},                     % author
    pdfsubject={blah},                        % subject of the document
    pdfkeywords={blah}, % list of keywords
    colorlinks=true,       % false: boxed links; true: colored links
    linkcolor=blue,       % color of internal links
    citecolor=black,       % color of links to bibliography
    filecolor=black,        % color of file links
    urlcolor=blue,        % color of external links
    linktoc=page            % only page is linked
} %
\def\myversion{0.0.1}
\date{\today}

\addto\captionsenglish{
    \renewcommand\listfigurename{Table of Figures}
    \renewcommand\listtablename{Table of Tables}
}


%% Setting the Header and Footer for all pages

\fancypagestyle{myblank}{
    \fancyhead{}
    \fancyfoot{}
    \fancyhead[L]{}
    \fancyhead[C]{}        %[CO, CE]
    \fancyhead[R]{}   %[RO, RE]
    
    \fancyfoot[L]{}
    \fancyfoot[C]{}
    \fancyfoot[R]{}
    
    \renewcommand{\headrule}{}
    \renewcommand{\footrule}{}
}

\fancypagestyle{mytitle}{
    \fancyhead{}
    \fancyfoot{}

    \fancyhead[L]{}
    \fancyhead[C]{\slshape \rightmark}        %[CO, CE]
    \fancyhead[R]{\textbf{LOGO}}   %[RO, RE]
    
    \fancyfoot[L]{}
    \fancyfoot[C]{{\small \copyright \the\year{}, Org\textsuperscript \textregistered, Inc. All Rights Reserved.}}
    \fancyfoot[R]{Page \thepage}
    
    \renewcommand{\headrule}
    {
        \hrule height 1pt
        \vspace{0.5pt}
        \hrule height 3pt
    }
    \renewcommand{\footrulewidth}{1pt}
}

\fancypagestyle{plain}{}

\fancypagestyle{myregular}{
    \fancyhead{}
    \fancyfoot{}

    \fancyhead[L]{}
    \fancyhead[C]{
        \fbox{\parbox[b][][b]{10cm}{
                \begin{center}
                    %\vspace{-10pt}
                    {\small \textbf{Line 1}}\\
                    {\small \textbf{Line 2}}\\
                    {\small \textbf{Version \myversion}}
                    \vspace{-11pt}
                \end{center}
            }}
    }        %[CO, CE]
    \fancyhead[R]{\textbf{LOGO}}   %[RO, RE]

    \fancyfoot[L]{\textbf{WTF}}
    \fancyfoot[C]{{\small \copyright \the\year{}, Org\textsuperscript \textregistered, Inc. All Rights Reserved.}}
    \fancyfoot[R]{Page \thepage}
    
    \renewcommand{\headrule}
    {
        \hrule height 3pt
    }
    \renewcommand{\footrulewidth}{1pt}
}

空白页面.tex

\pagestyle{myblank}

\begin{center}
    \hspace*{\fill} \break
    \vspace{4in}

    \textit{This page has been intentionally left blank.}

\end{center}

第1页.tex

\pagestyle{mytitle}

%% Beginning to work on content

\newtcolorbox{gradbox}[1][]{
    freelance,
    frame code={},
    interior code={
    \fill[top color=greyShade!45,bottom color=greyShade!5,middle color=greyShade!15]
        (interior.north west) rectangle (interior.south east);
    }
    outer arc=0pt,
    arc=0pt,
    boxrule=0pt,
    nobeforeafter,
    left=0pt,
    right=0pt,
    top=0pt,bottom=0pt,
    #1
}

%% Creating the title Page Content
\begin{center}
    \hspace*{\fill} \break
    \vspace{4cm}

    {\Huge \textbf{Ovolune}}\\

    \vspace{1cm}
    {\LARGE \textbf{A Document}}\\
    
    \vspace{2cm}
    {\LARGE \textbf{Version \myversion}}\\
    
    \vspace{1.5cm}
    {\Large \textbf{\today}}\\

    \vspace{5.4cm}
    %\begin{center}
    \fbox{\parbox[b][][b]{\linewidth}{
            \begin{gradbox}{}
                \begin{center}
                    \vspace{0.75cm}
                    {\Large \textbf{Org\textsuperscript \textregistered, Inc.}}\\
                    {\small Line}\\
                    {\small line}\\
                    \vspace{8pt}
                    {\large Phone:} {\small 0}\\
                    {\large Fax:} {\small 0}\\
                    {\large Email:}\href{mailto:}{[email protected]}\\
                    {\large website:}\href{www.org.com}{www.org.com}\\
                    \vspace{0.75cm}
                \end{center}
            \end{gradbox}
        }}

\end{center}

第2页

\chapter*{Disclaimer}

\thispagestyle{myregular}
\vspace{-0.7cm}

\noindent Some Disclaimer. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec hendrerit nisl elit, ut mollis quam tempor eget. Sed risus nisi, aliquet quis aliquam tincidunt, fringilla eu ante. Nulla vitae leo rutrum, fermentum turpis vel, mollis nisl. Maecenas quis nisi libero. Vivamus fringilla mauris ante, id sagittis nibh tincidunt in. Aenean posuere lectus magna, ac lobortis felis mattis sit amet. Cras vel hendrerit dolor. Duis a vulputate risus. Maecenas non augue vitae justo sollicitudin convallis. Donec facilisis dolor arcu, sed scelerisque magna auctor quis.

主文件.tex

\documentclass[a4paper,twoside]{report}
\usepackage{customPreamble}

\pagestyle{empty}

\begin{document}

%% Including the title page
\newpage
\input{Pages/Page1.tex}

%% Including a blank page
\newpage
\input{Pages/blankPage.tex}

%% Including the Disclaimer Chapter
\newpage
\input{Pages/Page2.tex}

%% Including a blank page
\newpage
\input{Pages/blankPage.tex}

%% Including the Disclaimer Chapter
\newpage
\input{Pages/Page2.tex}

\end{document}

更新

  1. scrreprt从(KOMA)级转换report
  2. 修改了plain页面样式,以便\chapter采用新的页面样式

问题

大部分页面样式均可成功应用,但页面样式下的脚规则除外myregular

在此处输入图片描述

答案1

在我发布的问题文件中,我必须更改名为自定义序言.sty如下:

\usepackage[outer=0.6in,headheight=77pt,top=3cm, bottom=2.5cm]{geometry}
\usepackage{listings}
\usepackage{underscore}
\usepackage[]{hyperref}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{color, colortbl}
\usepackage[many]{tcolorbox}
\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0pt}%{0.75pt}
\definecolor{headerYellow}{rgb}{0.96, 0.78, 0.36}
\definecolor{greyShade}{RGB}{0,20,20} % Color of the boxes behind the abstract and headings

\usepackage{titlesec}

\titleformat{\chapter}
{
    \Large% %change this size to your needs for the first line
    \bfseries}{\chaptertitlename\ \thechapter}{14pt}{%
    \Large %change this size to your needs for the second line
}
\titleformat*{\section}{\large\headingfont}

\hypersetup{
    %bookmarks=true,    % show bookmarks bar?
    pdftitle={blah},    % title
    pdfauthor={blah},                     % author
    pdfsubject={blah},                        % subject of the document
    pdfkeywords={blah}, % list of keywords
    colorlinks=true,       % false: boxed links; true: colored links
    linkcolor=blue,       % color of internal links
    citecolor=black,       % color of links to bibliography
    filecolor=black,        % color of file links
    urlcolor=blue,        % color of external links
    linktoc=page            % only page is linked
} %
\def\myversion{0.0.1}
\date{\today}

\addto\captionsenglish{
    \renewcommand\listfigurename{Table of Figures}
    \renewcommand\listtablename{Table of Tables}
}


%% Setting the Header and Footer for all pages

\fancypagestyle{myblank}{
    \renewcommand{\headrule}{}
    \renewcommand{\footrulewidth}{0pt}

    \fancyhead{}
    \fancyfoot{}

    \fancyhead[L]{}
    \fancyhead[C]{}        %[CO, CE]
    \fancyhead[R]{}   %[RO, RE]
    
    \fancyfoot[L]{}
    \fancyfoot[C]{}
    \fancyfoot[R]{}
}

\fancypagestyle{mytitle}{
    \renewcommand{\headrule}
    {
        \hrule height 1pt
        \vspace{0.5pt}
        \hrule height 3pt
    }
    \renewcommand{\footrulewidth}{1pt}

    \fancyhead{}
    \fancyfoot{}

    \fancyhead[L]{}
    \fancyhead[C]{\slshape \rightmark}        %[CO, CE]
    \fancyhead[R]{\textbf{LOGO}}   %[RO, RE]
    
    \fancyfoot[L]{}
    \fancyfoot[C]{{\small \copyright \the\year{}, Org\textsuperscript \textregistered, Inc. All Rights Reserved.}}
    \fancyfoot[R]{Page \thepage}
}

\fancypagestyle{plain}{}

\fancypagestyle{myregular}{
    \renewcommand{\headrule}
    {
        \hrule height 3pt
    }
    \renewcommand{\footrulewidth}{1pt}

    \fancyhead{}
    \fancyfoot{}

    \fancyhead[L]{}
    \fancyhead[C]{
        \fbox{\parbox[b][][b]{10cm}{
                \begin{center}
                    %\vspace{-10pt}
                    {\small \textbf{Line 1}}\\
                    {\small \textbf{Line 2}}\\
                    {\small \textbf{Version \myversion}}
                    \vspace{-11pt}
                \end{center}
            }}
    }        %[CO, CE]
    \fancyhead[R]{\textbf{LOGO}}   %[RO, RE]

    \fancyfoot[L]{\textbf{WTF}}
    \fancyfoot[C]{{\small \copyright \the\year{}, Org\textsuperscript \textregistered, Inc. All Rights Reserved.}}
    \fancyfoot[R]{Page \thepage}
}

使它对我有用的改变如下:

我应该\fancypagestyle{myblank}设置\footrulewidth0 分

\renewcommand{\headrule}{}
\renewcommand{\footrulewidth}{0pt}

结果如下(这就是我想要的): 在此处输入图片描述

相关内容