如何获取标题中的作者和章节名称;或者使用 fancyhdr?

如何获取标题中的作者和章节名称;或者使用 fancyhdr?

我想设置一个页眉/页脚,显示:

  1. 章节名称在奇数页;
  2. 偶数页上的作者姓名(不同章节的不同作者);
  3. 中央页脚中的页码。

任何帮助都将不胜感激。
谢谢。

更新:
MWE 定义为

\documentclass{book}  
\usepackage{blindtext}  
\usepackage{fancyhdr}  
\pagestyle{fancy}  
\begin{document}

\chapter{Wombat}  
Author Aa, And Author Bb  
\blindtext[5]  
\section{tabmow}  
\blindtext[5]  

\chapter{Capybara}  
Author Cc, And Author Dd  
\blindtext[5]  
\section{arabypac}  
\blindtext[5]  

\end{document}

答案1

下面介绍\chapterauthor如何设置和存储与您的 s 关联的作者\chapter。这允许您在部分中使用存储的详细信息\fancyhead[LE]

在此处输入图片描述

\documentclass{book}

\usepackage{blindtext}
\usepackage{fancyhdr}

\makeatletter
\newcommand{\chapterauthor}[1]{%
  \def\@chapterauthor{#1}% Store chapter authors
  {\bfseries #1}% Set chapter authors
  \par
}

\fancyhf{}% Clear header/footer
\fancyhead[RO]{\leftmark}% Chapter details in book
\fancyhead[LE]{\@chapterauthor}% Stored \chapterauthor details
\fancyfoot[C]{\thepage}
%\renewcommand{\headrulewidth}{0pt}% Remove header rule
%\renewcommand{\footrulewidth}{0pt}% Remove footer rule (default)
\pagestyle{fancy}
\makeatother

\begin{document}

\chapter{Wombat}
\chapterauthor{Author Aa, And Author Bb}
\blindtext[5]
\section{tabmow}
\blindtext[5]

\chapter{Capybara}
\chapterauthor{Author Cc, And Author Dd}
\blindtext[5]
\section{arabypac}
\blindtext[5]

\chapter*{Mara}
\chapterauthor{}% No chapter author
\blindtext[5]
\section{aram}
\blindtext[5]

\end{document}

答案2

阅读完花式高清包中,我完成了如下工作:

\documentclass[twoside]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{\thechapter.\ #1}{}}

\newcommand{\TheAuthor}{} % As given in documentation of **fancyhdr**
\newcommand{\Author}[1]{\renewcommand{\TheAuthor}{#1}}
\fancyhead{} % clear all fields
\fancyhead[CO]{\slshape \leftmark}
\fancyhead[CE]{\slshape \TheAuthor}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.6pt}

\begin{document}
\tableofcontents{}
\mainmatter % Begin numeric (1,2,3...) page numbering
\pagestyle{fancy} % Return the page headers back to the "fancy" style
\input{./Chap1/Chap1} % Include the chapters as separate files from the Chapters folder (first <Chap1> is folder and second one is file Chap1.tex)
\fancyhead{}
\end{document}

我的 Chap1.tex 是:

% Chapter 1  
\chapter{Introduction}  
\Author{PQR}  
\section{Introduction}  
\lipsum[1-22]  
\section{Background}  
\lipsum[1-22]  
\subsection{History}  
\lipsum[1-22]  

相关内容