Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I' writing my thesis in LyX with book (memoir) style. I would like to personalize the headers and footers but I cannot use the fancy package since I'm in the memoir style.

So (being a novice in LaTeX) I tried to use pre-existing code that I modified to create a new page style.

The headers work fine; I got the section and the subsections respectively on the even and odd pages. I also got the page number on the footer on both pages but I cannot add the chapter number on the footer.

How could I proceed to get the footer with the current chapter number on each page in addition to the pre-existing page number?

  \nouppercaseheads

    \makepagestyle{mystyle}

    \makeheadrule {mystyle}{\textwidth}{\normalrulethickness} 

    \setlength{\headwidth}{\dimexpr\textwidth+\marginparsep+\marginparwidth\relax}


    %head
    \makeevenhead{mystyle}{\small\leftmark}{}{} 
    \makeoddhead{mystyle}{}{}{\small\rightmark}

    %foot
    \makeevenfoot {mystyle} {\small\thepage} {\small\leftmark} {}
    \makeoddfoot {mystyle} {} {\small\leftmark} {\small\thepage}

    \makeatletter

    \makepsmarks{mystyle}{%
      \createmark{section}{left}{shownumber}{}{\space}
      \createmark{subsection}{right}{shownumber}{}{\space}
      \createmark{chapter}{right}{shownumber}{\@chapapp\ }{\space }}

    \makeatother

    \pagestyle{mystyle}
share|improve this question
1  
Welcome to TeX.sx! –  texenthusiast Jan 7 '13 at 0:39
add comment

1 Answer

As \chapter starts a new page, there is not really a need to use a marks register. A conventional macro is sufficient. The following example uses \mychapterfoot that holds the string with the chapter/appendix title for the footer. Class memoir defines \f@rhdr that holds the header version of the chapter title. Hook points are

  • \memendofchapterhook for \chapter without star.
  • \memchapstarinfo for \chapter* with star before \appendix.
  • \memappchapstarinfo for \chapter after \appendix.

Also the marks register for \section and \subsection titles should be cleared to prevent leaking those titles from the previous chapter. Since the first page of a chapter has usually a different page style and a \subsection title is not likely to be needed in the headers on that page, calling \markboth{}{} clears the marks register.

Example:

\documentclass{memoir}

\makeatletter
\newcommand*{\mychapterfoot}{}
\g@addto@macro\memendofchapterhook{%
  \protected@xdef\mychapterfoot{%
    \@chapapp\ \thechapter\ \f@rhdr
  }%
  \markboth{}{}%
}
\let\org@memappchapstarinfo\memappchapstarinfo
\renewcommand{\memappchapstarinfo}[2]{%
  \org@memappchapstarinfo{#1}{#2}%
  \protected@xdef\mychapterfoot{\@chapapp\ \f@rhdr}%
  \markboth{}{}%
}
\let\org@memchapstarinfo\memchapstarinfo
\renewcommand*{\memchapstarinfo}[2]{%
  \org@memchapstarinfo{#1}{#2}%
  \protected@xdef\mychapterfoot{\@chapapp\ \f@rhdr}%
  \markboth{}{}%
}
\makeatother

\nouppercaseheads

\makepagestyle{mystyle}

\makeheadrule {mystyle}{\textwidth}{\normalrulethickness}

\setlength{\headwidth}{\dimexpr\textwidth+\marginparsep+\marginparwidth\relax}

%head
\makeevenhead{mystyle}{\small\leftmark}{}{}
\makeoddhead{mystyle}{}{}{\small\rightmark}

%foot
\makeevenfoot {mystyle} {\small\thepage} {\small\mychapterfoot} {}
\makeoddfoot {mystyle} {} {\small\mychapterfoot} {\small\thepage}

\makeatletter

\makepsmarks{mystyle}{%
  \createmark{section}{left}{shownumber}{}{\space}%
  \createmark{subsection}{right}{shownumber}{}{\space}%
  \renewcommand*{\chaptermark}[1]{}%
}

\makeatother

\pagestyle{mystyle}

\setcounter{secnumdepth}{3}

\begin{document}
\chapter{Introduction}
\section{Section A}   
\subsection{Subsection B}
\newpage
\null   
\newpage
\null   
\chapter*{Nix}
\newpage
\null   
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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