0

I am having problems getting the section name displayed on the top of my pages. I know \leftmark is the proper way to do this, but I would like that the section name is only displayed when no subsection name is present, and that it is not capitalized.

Explained in another way: This is a document of 3 pages. The first page has nothing in the header, I would like it to have "1 A section" in the header, but the following pages should remain the same:

\documentclass[twoside]{article}
\usepackage{fancyhdr}

%Header defined \pagestyle{fancy} \fancyhf{} \fancyhead[RO]{\rightmark} \fancyhead[LE]{\rightmark}

\begin{document} \section{A section}

\newpage

\subsection{A subsection}

\newpage

\subsection{Another subsection}

\end{document}

Thanks in advance.

1 Answers1

2

You must redefine \sectionmark to fill the right part of the mark. \rightmark always use the first mark, so if you have to sections or subsections on a page, you will get the first.

\documentclass[twoside]{article}
\usepackage{fancyhdr}

\renewcommand*\subsectionmark[1]{}

%Header defined \pagestyle{fancy} \fancyhf{} \fancyhead[RO]{\rightmark} \fancyhead[LE]{\rightmark}

\renewcommand*\sectionmark[1]{% \markboth{\thesection\hskip 1em\relax#1}{\thesection\hskip 1em\relax#1}}

\begin{document} \section{A section} \section{B section} \newpage

\subsection{A subsection} \subsection{B subsection} \newpage

\subsection{Another subsection}

\end{document}

Ulrike Fischer
  • 327,261