答案1
\leftmark
使用(对于\section
s)和\rightmark
(对于\subsection
s)设置标题:
\documentclass[twoside]{article}
\usepackage{fancyhdr,lipsum}
\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\fancyhead[RO,LE]{\slshape\leftmark}
\fancyhead[RE,LO]{\slshape\rightmark}
\fancyfoot[C]{\thepage}
\begin{document}
\sloppy % Just for this example
\tableofcontents
\section{First section}\lipsum[1-10]
\subsection{First subsection}\lipsum[11-20]
\subsection{Second subsection}\lipsum[21-30]
\subsection{Third subsection}\lipsum[31-40]
\subsection{Last subsection}\lipsum[41-50]
\section{Second section}\lipsum[1-10]
\subsection{First subsection}\lipsum[11-20]
\subsection{Second subsection}\lipsum[21-30]
\subsection{Third subsection}\lipsum[31-40]
\subsection{Last subsection}\lipsum[41-50]
\section{Third section}\lipsum[1-10]
\subsection{First subsection}\lipsum[11-20]
\subsection{Second subsection}\lipsum[21-30]
\subsection{Third subsection}\lipsum[31-40]
\subsection{Last subsection}\lipsum[41-50]
\section{Last section}\lipsum[1-10]
\subsection{First subsection}\lipsum[11-20]
\subsection{Second subsection}\lipsum[21-30]
\subsection{Third subsection}\lipsum[31-40]
\subsection{Last subsection}\lipsum[41-50]
\end{document}