# How do I make a subsection title visible in a header on page with chapter / section

Could someone please give me a hand to correctly use \markboth{}{} within redefinition of the \sectionmark? I am struggling to apply the second parameter in \markboth. The article I am writing needs to have both section and subsection titles on all pages. I read Header not displaying correctly on chapter page due to subsection and understood that \chapter or \section commands make the \markright field empty and therefore subsection does not appear on pages where \chapter or \section is issued. I still cannot understand how to make this work. I will be grateful for any help.

PS. Below is the LaTeX code. I am compiling the article using XeLaTeX.

\documentclass[11pt]{article}
\special{papersize=210mm,297mm}

\title{\bfseries Factor Analysis}
\author{J. Smith}

% Set font
\usepackage{unicode-math}
\setmainfont[Ligatures=TeX]{Cambria}
\setmathfont{Cambria Math}

% if then
\usepackage{ifthen}

% Multi columns
%\usepackage{paralist} % Used for the "compactitem" environment which makes bullet points with less space between them
\usepackage{multicol} % Used for the two-column layout of the document
\setlength{\columnsep}{20pt}

\pagestyle{fancy} % All pages have headers and footers
\fancyhf{} % clear all headers and footers - equivalent to %\fancyhead{} and \fancyfoot{}
\renewcommand{\footrulewidth}{0.4pt}
\newcommand{\mymarks}{
\ifthenelse{\equal{\rightmark}{}} % is \rightmark empty?
{\leftmark} % when empty
{\leftmark\ --\ \itshape\rightmark} % when not empty
}
\renewcommand{\sectionmark}[1]{\markboth{\thesection.\ #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}
\fancyfoot[C]{\thepage} % Custom footer text

\usepackage{graphicx}
\usepackage{url} % allows escaping special characters inside a hyper links in a bibliography such as %20 etc.
\usepackage[round]{natbib}
\usepackage{setspace}
\usepackage[format=hang,font=small,labelfont=bf]{caption} % Custom captions under/above floats in tables or figures

\usepackage{hyperref}
\hypersetup{
bookmarks=false,         % show bookmarks bar?
pdftoolbar=true,        % show Acrobat’s toolbar?
pdffitwindow=false,     % window fit to page when opened
pdfstartview={FitH},    % fits the width of the page to the window
pdftitle={Exposure response relationship to noise in the presence of vibration},    % title
pdfauthor={Zbigniew Koziel},     % author
pdfsubject={Environmental Noise and Vibration},   % subject of the document
pdfcreator={Zbigniew Koziel},   % creator of the document
pdfproducer={Zbigniew Koziel}, % producer of the document
pdfkeywords={noise} {vibration} {exposure response-relationship}, % list of keywords
pdfnewwindow=true,      % links in new window
citecolor=blue,
urlcolor=blue,
filecolor=black      % color of file links
}

% Change default commands
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}

% New commands
\newcommand{\defaultvspacing}{\doublespacing}
\newcommand{\compactvspacing}{\onehalfspacing}
\newcommand{\tidyvspacing}{\singlespacing}
\newcommand{\myterm}[2]{$#1_{\mathrm{#2}}$}
\newcommand{\defvspace}{12pt}
\newcommand{\clearthepage}{\clearpage} % depending on one or two side
\newcommand{\mysection}[2]{\clearthepage\markright{#2}\section{#1}}

\begin{document}
\tidyvspacing
\maketitle
\begin{abstract}
The abstract
\end{abstract}
\tableofcontents

\compactvspacing
\include{introduction}
\include{conceptual_view}
\include{fa_and_sm}
\include{the_factor_model}
\include{interpeting_factor_tables}

\bibliography{thesis} % Here from this place, the Bibliography should appear !
% \bibliographystyle{plain} % Standard commands for BiBTeX
\bibliographystyle{plainnat} % Extended commands from package natbib
\end{document}


Yes, the problem with marks for short sections and subsections is a well known problem with LaTeX marks. If you are willing to use another package, here's a solution using titlesec with its options pagestyles and extramarks (I removed parts of the original code that were not relevant to the problem discussed):

\documentclass[11pt]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{lipsum}% just to generate text for the example
\usepackage{ifthen}
\usepackage[pagestyles,extramarks]{titlesec}

\settitlemarks*{section,subsection}

\newpagestyle{mystyle}{
\setfoot{}{\thepage}{}
}
\pagestyle{mystyle}

\begin{document}

\section{Test Section One}
\lipsum[4]
\subsection{Test Subsection One}
\lipsum[1]
\section{Test Section Two}
Some test text here

\end{document}


• Thank you for this example. I am quite a beginner in LaTeX and I knew there was the titlesec package but I did not realise it could also work for settings headings footnotes.I understand that three parameters in both commands \sethead{}{}{} and \setfoot{}{}{} correspond to left, centre, and right parts of heading/footnote which are also left, centre and right aligned. – Celdor Jun 2 '13 at 2:47
• @ZikO yes, you are right about the meaning for the three arguments. There are also three optional arguments in case the twoside option is in use. \sethead[even-left][even-center][even-right]{odd-left}{odd-center}{odd-right}, and analogously for \setfoot. – Gonzalo Medina Jun 2 '13 at 3:03