3

I'm using memoir for an onesided document, but I wanted to have both the chapter and section numbers and names in the header.

I'm using this to achieve it (from Including both chapter name and name of section in header using memoir)

\pagestyle{ruled}
\makeoddhead{ruled}{\sffamily\leftmark}{}{\sffamily\rightmark}

This works great most of the time, however for the ToC and bibliography, both of which are two pages long, I have the same label twice in the header, which looks terrible.

I would like to only show the \rightmark if it's different from the \leftmark. Or somehow change the labeling of those two things. For example it works OK in introduction, which is an \unnumberedchapter and has no \section. I've tried changing \bibsection to \unnumberedchapter but that didn't help.

Thanks.

1 Answer 1

5

I'm beginning to think that for any question, there's always an answer inspired by egreg (On testing two fully expanded character strings for equality):

\documentclass[oneside]{memoir}

\usepackage{pdftexcmds} % https://tex.stackexchange.com/questions/59565/on-testing-two-fully-expanded-character-strings-for-equality
\makeatletter
\newcommand*{\test}[2]{%
  \ifnum\pdf@strcmp{#1}{#2}=\z@ \relax \else #2 \fi
}
\makeatother

\pagestyle{ruled}
\makeoddhead{ruled}{\sffamily\leftmark}{}{\sffamily\test{\leftmark}{\rightmark}}

\usepackage{lipsum}

\newcommand{\makechapter}{
\chapter{foo}
\section{foobar}
\lipsum[1-12]
}

\begin{document}

\tableofcontents

\makechapter
\makechapter
\makechapter
\makechapter
\makechapter
\makechapter
\makechapter
\makechapter
\makechapter
\makechapter
\makechapter
\makechapter
\makechapter
\makechapter

\end{document}

enter image description here

enter image description here

4
  • 1
    I give good inspirations, it seems. ;-)
    – egreg
    May 10, 2014 at 22:27
  • @egreg Good solutions too. And at times good lessons, criticisms ..... :).
    – user11232
    May 11, 2014 at 0:07
  • Works perfectly, thanks! I tried something like this but didn't properly expand the macros before comparison which didn't work so I gave up on that idea.
    – lacop
    May 11, 2014 at 11:20
  • Proper use of \expandafter has always been a sticking point for me, too. I'll certainly go for this method in the future. May 11, 2014 at 13:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .