页眉带有章节标题,而编号位于页脚中?

页眉带有章节标题,而编号位于页脚中?

如何在页眉上放置章节/小节的标题和编号,同时在页脚中放置编号?

\pagestyle{...} 不允许这种组合。

答案1

这里有一种方法可以解决一些问题(例如在标题中添加带星号的部分和小节 - 或者如果经过修改,甚至在目录中添加 -)

\documentclass[twoside]{article}
\usepackage{lipsum}
\usepackage{fancyhdr}
%\fancyhead[CO,CE]{}
\fancyhead[LO,RE]{\scshape\leftmark}
\fancyhead[RO,LE]{\itshape\rightmark}
\let\oldsection\section
\let\oldsubsection\subsection
\makeatletter
\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\def\@StarredWith[#1]#2{%
\oldsection*{#2}%
\renewcommand\leftmark{#1}%
}
\def\@StarredWithout#1{
\oldsection*{#1}%
\renewcommand\leftmark{#1}
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldsection[#1]{#2}%
\renewcommand\leftmark{\thesection~#1}%
}
\def\@nonStarredWithout#1{%
\oldsection{#1}%
\renewcommand\leftmark{\thesection~#1}%
}

\def\subsection{%
\@ifstar{\@StarredS}{\@nonStarredS}%
}
\def\@StarredS{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to use them for the hearder}\@StarredSWith}%
{\@StarredSWithout}%
}      
\def\@StarredSWith[#1]#2{%
\oldsubsection*{#2}%
\renewcommand\rightmark{#1}%
}
\def\@StarredSWithout#1{
\oldsubsection*{#1}%
\renewcommand\rightmark{#1}
}
\def\@nonStarredS{%
\@ifnextchar[%
{\@nonStarredSWith}%
{\@nonStarredSWithout}%
}
\def\@nonStarredSWith[#1]#2{%
\oldsubsection[#1]{#2}%
\renewcommand\rightmark{\thesubsection~#1}%
}
\def\@nonStarredSWithout#1{%
\oldsubsection{#1}%
\renewcommand\rightmark{\thesubsection~#1}%
}
\makeatother

\pagestyle{fancy}

\title{Test redefined sections}

\author{Kostis Leledakis}

\begin{document}
\maketitle
\tableofcontents
\clearpage

\section{A section}
\lipsum[1-8]
\subsection{A subsection}
\lipsum[1-6]
\subsection*{A starred subsection}
\lipsum[1-8]
\subsection{Another numbered  subsection}
\lipsum[1-6]
\subsection*{Another starred subsection}
\lipsum[1-8]
\subsection[Short title of subection \thesubsection]{Another numbered  subsection with short title}
\lipsum[1-6]
\section{Another section}
\lipsum[1-6]
\section*{A starred section}
\lipsum[1-8]
\subsection{A subsection}
\lipsum[1-6]
\subsection*{A starred subsection}
\lipsum[1-8]
\subsection{Another numbered  subsection}
\lipsum[1-6]
\subsection*{Another starred subsection}
\lipsum[1-8]
\subsection[Short title of subection \thesubsection]{Another numbered  subsection with short title}
\lipsum[1-6]
\section{Another numbered  section}
\lipsum[1-6]
\section*{Another starred section}
\lipsum[1-8]
\section[Short title of section \thesection]{Another numbered  section with short title}
\lipsum[1-6]
\section*[Short title of starred section]{Another starred  section with short title}
\lipsum[1-8]
\end{document}

附言:是的答案已修改。

相关内容