如何使節*出現在標題中

如何使節*出現在標題中

我正在使用文章類和我使用該包的自訂包fancyhdr。我使用以下方法定義我的標題:

\fancyhead[CO,CE]{}
\fancyhead[RO,RE]{\scshape\leftmark}

問題是我有幾個部分*。在每個節 * 頁面,標題顯示前一個節的名稱,而不是節 * 的名稱。

我不知道如何改變這一點,任何幫助將不勝感激。

答案1

這是我舊答案的一種方法這裡:

\documentclass{article}
\usepackage{lipsum}
\usepackage{fancyhdr}
%\fancyhead[CO,CE]{}
\fancyhead[R]{\scshape\leftmark}
\let\oldsection\section
\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{#1}%
}
\def\@nonStarredWithout#1{%
\oldsection{#1}%
\renewcommand\leftmark{#1}%
}
\makeatother

\pagestyle{fancy}

\title{Test redefined sections}

\author{Kostis Leledakis}

\begin{document}
\maketitle
\tableofcontents
\clearpage

\section{A section}
\lipsum[1-8]
\section{Another section}
\lipsum[1-6]
\section*{A starred section}
\lipsum[1-8]
\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}

在此輸入影像描述

在此輸入影像描述

在此輸入影像描述

相關內容