我有一个相当复杂的文档。该fancyhdr
包用于格式化页眉和页脚。由于我需要多种样式,因此我定义了三种不同的样式:
\fancypagestyle{default}{
\fancyhf{} % clear all header fields
\fancyhead[RO]{\nouppercase{\rightmark}}
\fancyhead[LE]{\nouppercase{\leftmark}}
\lfoot[\thepage]{}
\rfoot[]{\thepage}
\renewcommand{\headrulewidth}{0.2pt}
}
\fancypagestyle{page_only}{
\fancyhf{} % clear all header fields
\lfoot[\thepage]{}
\rfoot[]{\thepage}
}
\fancypagestyle{plain}{
\fancyhf{} % clear all header fields \lfoot[\thepage]{}
\rfoot[]{\thepage}
\renewcommand{\headrulewidth}{0pt}% Line at the header invisible
}
\renewcommand{\headrulewidth}{0pt}
%Redefine chapter by adding fancy as the chapter title page page-style
\makeatletter
\let\stdchapter\chapter
\renewcommand*\chapter{%
\@ifstar{\starchapter}{\@dblarg\nostarchapter}}
\newcommand*\starchapter[1]{%
\stdchapter*{#1}
\thispagestyle{plain}
\markboth{\MakeUppercase{#1}}{}
}
\def\nostarchapter[#1]#2{%
\stdchapter[{#1}]{#2}
\thispagestyle{default}
}
\makeatother
一般情况下,所有样式都可以访问。但是,如果我使用该default
样式,章节和部分名称不会更新。我不知道为什么会发生这种情况。
以下是序言的完整列表:
\documentclass[10pt,twoside,openright]{extreport}
\usepackage{tgtermes}
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[utf8]{inputenc} % direct input of unicode chars like äöüß
\usepackage[OT1]{fontenc}
\usepackage[ngerman, english]{babel}
\usepackage{nameref}
\usepackage{color}
\usepackage{subcaption}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{url}
\usepackage{listings}
\usepackage{float}
\usepackage[alsoload=synchem, binary-units=true]{siunitx}
\sisetup{group-separator = {,}}
\usepackage{hyphenat}
\usepackage{booktabs}
\usepackage[hang]{footmisc}
\usepackage{rotating}
\usepackage{afterpage}
\newcommand\blankpage{%
\null
\thispagestyle{empty}%
\addtocounter{page}{-1}%
\newpage}
\setlength{\footnotemargin}{6pt}
\usepackage{titlesec}
\titleformat{\chapter}{\Huge\bfseries}{\chaptername\ \thechapter}{0pt}{\vskip 0pt\raggedright}%
%\titlespacing*{\chapter}{0pt}{-16pt}{16pt}
\titlespacing*{\chapter}{0pt}{0pt}{0pt}
\titlespacing*{\section}{0pt}{0pt}{0pt}
\titlespacing*{\subsection}{0pt}{0pt}{0pt}
%\titlespacing*{\subsubsection}{0pt}{20pt}{20pt}
\setlength{\belowcaptionskip}{-16pt plus 3pt minus 2pt}
\usepackage[labelfont=bf,font={small,it}]{caption}
\usepackage{fancyhdr}
\usepackage{algpseudocode}
% Einrückung für Quellcode
\algrenewcommand\algorithmicindent{.5em}
\floatname{algorithm}{Procedure}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\let\oldReturn\Return
\renewcommand{\Return}{\State\oldReturn}
\usepackage{tocloft}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\setlength{\cftfigindent}{0pt} % remove indentation from figures in lof
\setlength{\cfttabindent}{0pt} % remove indentation from tables in lot
\usepackage{hyperref}
\hypersetup{
colorlinks,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black
}
\usepackage[
% showframe=true, %Margins visualisieren
% papersize={17cm,24cm},
paperheight=24cm,
paperwidth=17cm,
lmargin=20mm, %Margin left
rmargin=18mm, %Margin right
tmargin=30mm, %Margin top
bmargin=25mm, %Margin bottom
headsep=10mm
% marginparwidth=1cm, %Notizrand rechts
% marginparsep=0.5cm,
% paper=a5paper,
% includehead, % Kopfzeile in Berechnung einbeziehen
% includemp % Marginpar in die Berechnung mit einbeziehen
]{geometry}
% Print frame around page components
%\usepackage{showframe}
\fancypagestyle{default}{
\fancyhf{} % clear all header fields
\fancyhead[RO]{\nouppercase{\rightmark}}
\fancyhead[LE]{\nouppercase{\leftmark}}
\lfoot[\thepage]{}
\rfoot[]{\thepage}
\renewcommand{\headrulewidth}{0.2pt}
}
\fancypagestyle{page_only}{
\fancyhf{} % clear all header fields
\lfoot[\thepage]{}
\rfoot[]{\thepage}
}
\fancypagestyle{plain}{
\fancyhf{} % clear all header fields \lfoot[\thepage]{}
\rfoot[]{\thepage}
\renewcommand{\headrulewidth}{0pt}% Line at the header invisible
}
\renewcommand{\headrulewidth}{0pt}
%Redefine chapter by adding fancy as the chapter title page page-style
\makeatletter
\let\stdchapter\chapter
\renewcommand*\chapter{%
\@ifstar{\starchapter}{\@dblarg\nostarchapter}}
\newcommand*\starchapter[1]{%
\stdchapter*{#1}
\thispagestyle{plain}
\markboth{\MakeUppercase{#1}}{}
}
\def\nostarchapter[#1]#2{%
\stdchapter[{#1}]{#2}
\thispagestyle{default}
}
\makeatother
\usepackage[dvipsnames]{xcolor}
\hyphenation{na-no-crys-tal-lo-gra-phy indexmajiq}
\usepackage[parfill]{parskip}
\newenvironment{abstractpage}
{\cleardoublepage\vspace*{\fill}\thispagestyle{empty}}
{\vfill\cleardoublepage}
\renewenvironment{abstract}[1]
{\bigskip\selectlanguage{#1}%
\begin{center}\bfseries\abstractname\end{center}}
{\par\bigskip}
\usepackage{setspace}
答案1
经过大量调试后,我发现无法使用 覆盖“空”样式fancypagestyle
。因此将模板重命名为custom_empty
,现在一切正常。