使用 fancyhdr 的两种不同布局

使用 fancyhdr 的两种不同布局

我想为我的文档设置两种不同的布局(即页眉)。该文档是两列字典。第一部分是包含章节和节的介绍,第二部分是字典本身,其中页眉由页面上的第一个和最后一个词条组成。我不知道如何设置页眉中带有章节的第一个布局,以及如何将其更改为不同的布局。以下是代码:

\documentclass[twocolumn]{book}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage[icelandic, czech, english]{babel}
\usepackage[utf8x, utf8]{inputenc}
\newcommand{\entry}[2]{\hangpara{2em}{1}\textsf{\textbf{#1}}\ #2\markboth{#1}{#1}\par}\nopagebreak[4]
\pagestyle{fancy}
\newcommand*{\dictchar}[1]{\centerline{\LARGE\textbf{#1}}\par}
\fancyhf{}
\fancyhead[LE,RO]{\textsf{\textbf{\rightmark\ -- \leftmark}}}
\fancyhead[LO,RE]{\textsf{\textbf{\thepage}}}
\usepackage{fix2col}
\begin{document}\maketitle
\thispagestyle{plain}
\chapter*{1. First chapter}
\section*{1.1 First section}
...

答案1

您可以使用命令\fancypagestyle来定义标题布局。第一个参数是布局的名称,第二个参数包含您想要应用的命令。之后,您可以通过\pagestyle和选择任何自定义布局\thispagestyle

例子:

\documentclass{book}
\usepackage{fancyhdr}
\fancypagestyle{basicstyle}{%
  \fancyhf{}
  \fancyhead[LE,RO]{\rightmark}
  \fancyhead[LO,RE]{\leftmark}
  \fancyfoot[C]{\thepage}
  \renewcommand{\headrulewidth}{0.4pt}
  \renewcommand{\footrulewidth}{0pt}}
\fancypagestyle{otherstyle}{%
  \fancyhf{}
  \fancyhead[C]{header}
  \renewcommand{\headrulewidth}{0pt}}
\pagestyle{basicstyle}
\begin{document}
\chapter{One}
\section{First section}
\thispagestyle{otherstyle}
\clearpage
text
\end{document}

相关内容