# Question

How can I put the section name in the top right header on every page of my custom style mainmatter, but without the number. I do not want any subsections: ONLY SECTIONS.

## Problem

First of all, I have an incomplete understanding of the mark commands in LaTeX:

• \leftmark (higher-level)=whatever this means... sections? chapters?
• \rightmark (lower-level)=whatever this means... subsections?
• \markboth

This was taken from chapter 9 The scoop on LaTeX's marks of the fancyhdr documentation version March 2, 2004.

Secondly, I cannot seem to get the \renewcommand{\sectionmark}[1]{\markright{#1}} of this question to work.

## Example

\documentclass[10pt]{article}
\usepackage[quiet]{fontspec}
% !TEX TS-program = XeLaTeX
\setmainfont{SourceSansPro}[%
Extension = .otf ,
UprightFont = *-Regular ,
ItalicFont = *-RegularIt ,
BoldFont = *-Bold ,
BoldItalicFont = *-BoldIt ]
\usepackage[%
a4paper,
foot=2.3cm,  % distance from top of footer to block of text aka \footskip
%   heightrounded,       % ensure an integer number of lines
marginparwidth=2cm,  % right marginal note width
marginparsep=2mm,    % distance from text block to marginal note box
%   height=\textheight,  % height of the text block
%   width=\textwidth,    % width of the text block
top=2.5cm,           % distance of the text block from the top of the page
bottom=3cm,
left=2.5cm,
right=2.5cm,
%    showframe,           % show the main blocks
%    verbose,             % show the values of the parameters in the log file
]{geometry}

\usepackage{fancyhdr}

\pagestyle{fancy} % This must be here, because defaults are set and renewcommand for section marks will work.
\renewcommand{\sectionmark}[1]{\markright{#1}}

%Fancyhdr Styles
\fancypagestyle{frontmatter}{%
\fancyhf{} % clear all fields
\lfoot{}
\cfoot{}
\rfoot{}
}%
\fancypagestyle{mainmatter}{%
\fancyhf{} % clear all fields
\lfoot{}
\cfoot{}
\rfoot{}
}%

\begin{document}
\pagestyle{frontmatter}
\section{Monkey}
\newpage
\pagestyle{mainmatter}
\section{Yack}
\newpage
\section{Alpine ibex}
\end{document}

• Well, you never use \rightmark, so how'd you expect it appears somewhere? – egreg Jan 9 '15 at 10:47
• @egreg +1 Buahaha I actually laughed after reading that comment! This is very true :D – Jonathan Komar Jan 9 '15 at 10:55

You have to change \leftmark to \rightmark in the definition of mainmatter pagestyle.

Also you have to nullify the effect of \subsectionmark

\renewcommand{\subsectionmark}[1]{}


MWE

\documentclass[10pt]{article}
\usepackage[quiet]{fontspec}
% !TEX TS-program = XeLaTeX
\setmainfont{SourceSansPro}[%
Extension = .otf ,
UprightFont = *-Regular ,
ItalicFont = *-RegularIt ,
BoldFont = *-Bold ,
BoldItalicFont = *-BoldIt ]
\usepackage[%
a4paper,
foot=2.3cm,  % distance from top of footer to block of text aka \footskip
%   heightrounded,       % ensure an integer number of lines
marginparwidth=2cm,  % right marginal note width
marginparsep=2mm,    % distance from text block to marginal note box
%   height=\textheight,  % height of the text block
%   width=\textwidth,    % width of the text block
top=2.5cm,           % distance of the text block from the top of the page
bottom=3cm,
left=2.5cm,
right=2.5cm,
%    showframe,           % show the main blocks
%    verbose,             % show the values of the parameters in the log file
]{geometry}

\usepackage{fancyhdr}

\usepackage{lipsum}

\pagestyle{fancy} % This must be here, because defaults are set and renewcommand for section marks will work.
\renewcommand{\sectionmark}[1]{\markright{#1}}
\renewcommand{\subsectionmark}[1]{}

%Fancyhdr Styles
\fancypagestyle{frontmatter}{%
\fancyhf{} % clear all fields
\lfoot{}
\cfoot{}
\rfoot{}
}%
\fancypagestyle{mainmatter}{%
\fancyhf{} % clear all fields
\lfoot{}
\cfoot{}
\rfoot{}
}%

\begin{document}
\pagestyle{frontmatter}
\section{Monkey}
\lipsum[1-20]
\newpage
\pagestyle{mainmatter}
\section{Yack}
\lipsum[1-20]
\newpage
\section{Alpine ibex}
\subsection{A subsection}
\lipsum[1-20]
\end{document}


Output:

• Could you please explain what "higher-level" and "lower-level" means? It is one aspect of the question you did not address. Am I right with my assumption? – Jonathan Komar Feb 29 '16 at 7:55