2

I am having some trouble getting the command \makepsmarks behave as I want it to behave. I would like to have the section titles in the header behave as follows: No section titles should be displayed until the second page of a section. When one section stops in the middle of the page, I want the title in the header to be from that section, and not the section beginning on the page.

If you compile my minimal example and look on page 3, there should not be a section title in the header. On page 5 the section title should remain section one until the next page, because section one ends on that page.

I have tried to fiddle around with the both, left and right commands and changed the \leftmark and \rightmark commands around, but I haven't found a solution, so I hope you can help.

\documentclass[12pt,a4paper,onecolumn,oneside,final]{memoir}
\usepackage{multicol}
\usepackage[english]{babel}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[textwidth=10cm,textheight=22cm]{geometry}
\usepackage{calc}
\usepackage{lipsum}


\makepagestyle{HDR}
\makepsmarks{HDR}{\nouppercaseheads 
\createmark{chapter}{left}{nonumber}{}{\space}
\createmark{section}{right}{nonumber}{}{\space} 
\makeheadrule{HDR}{10cm}{\normalrulethickness}
}
\makeoddhead{HDR}{\small\normalfont\mdseries\textsc{\leftmark}\hskip.3cm\vrule\hskip.3cm\bfseries\rightmark}{}{}
\makeoddfoot{HDR}{}{\thepage}{}

\begin{document}
\pagestyle{HDR}
\chapter{Chapter One}
\lipsum
\section{Section One}
\lipsum
\section{Section Two}
\lipsum
\end{document}
2

You may make \rightmark use \topmark instead of \firstmark, but things will go wrong if a section starts at the top of a page. You can fix this (not guaranteed to work in any situation, though) by emitting a mark als before the section:

\documentclass[12pt,a4paper,onecolumn,oneside,final]{memoir}
\usepackage[textwidth=10cm,textheight=22cm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[latin]{babel}% just to avoid bad hyphenation

\usepackage{lmodern}
\usepackage{microtype} % for better results
\usepackage{xparse}

\usepackage{calc}
\usepackage{multicol}
\usepackage{lipsum}

\makepagestyle{HDR}
\makepsmarks{HDR}{%
  \nouppercaseheads
  \createmark{chapter}{left}{nonumber}{}{\space}%
  \createmark{section}{right}{nonumber}{}{\space}%
  \makeheadrule{HDR}{10cm}{\normalrulethickness}%
}
\makeoddhead{HDR}{%
  \small\normalfont\mdseries
  \textsc{\leftmark}%
  \hspace{.3cm}\vrule\hspace{.3cm}%
  \textbf{\rightmark}%
}{}{}
\makeoddfoot{HDR}{}{\thepage}{}

\makeatletter
\renewcommand{\rightmark}{\expandafter\@rightmark\topmark\@empty\@empty}
\makeatother

\let\memoirsection\section
\RenewDocumentCommand{\section}{oom}{%
  \markright{#3}% emit a mark also before the section
  \IfNoValueTF{#1}
    {\memoirsection{#3}}
    {\IfNoValueTF{#2}
      {\memoirsection[#1]{#3}}
      {\memoirsection[#1][#2]{#3}}%
    }%
}


\begin{document}
\pagestyle{HDR}
\chapter{Chapter One}
\lipsum
\section{Section One}
\lipsum
\section{Section Two}
\lipsum
\lipsum[1-2]
\section{Section Three}
\lipsum[1]

\end{document}

enter image description here enter image description here enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.