4

My problem follows from my difficulties with the english explanations on the marks, from the readmes of fancyhd or titleps, in order to modify the headers. I do not understand the business behind the marks and the ones introduced by the extramarks option.

From what I gather from its readme, the titleps package has a starred version of the marks permitting to correctly taking into account the very first subsection when it is on the same page as the the section title. This solves the bug of LaTeX (which I do not fully follows too).

I do not prefer one package over the other, but the titleps gets me closer to what I want. Before the MWE, my wish is to have, with

\documentclass[twoside, a4paper, 11pt]{article}

on every page:

  • top left = \thesection--sectiontitle

  • top middle = \thepage

  • top right = \thesubsection--subsectiontitle but there is a problem when we change the section, see below.

  • bottom middle = \the page

For the ToC and the bibliography, I want only "Table of Content" in the top left position and the page in the top right.

With this MWE copied directly from the readme,

\documentclass[twoside, a4paper, 11pt]{article}
\usepackage[topmarks, extramarks]{titleps}
\settitlemarks*{section,subsection}


\newpagestyle{funny}{
\setfoot{\toptitlemarks Top is \thesubsection}
{\firsttitlemarks First is \thesubsection}
{\bottitlemarks Bot is \thesubsection}
\sethead{\firstextramarks{section}\thesection---\sectiontitle}
{\firstextramarks{subsection}\thesubsection---\subsectiontitle}
{\thepage}
}


\pagestyle{funny}



\usepackage{lipsum}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\tableofcontents

\newpage

\section{first section}

\lipsum[1-3]
\subsection{first subsetion of the first section}
\lipsum[1-3]
\subsection{second subsetion of the first section}

\lipsum[1-3]
\subsection{third subsetion of the first section}
\lipsum[1-11]



\section{second section}
\lipsum[1-11]
\subsection{first subsetion of the second section}
\lipsum[1-3]




\subsection{second subsetion of the second section}

\lipsum[1-11]
\subsection{third subsetion of the second section}
\lipsum[1-11]


\section{thirs section}
%\lipsum[1-3]
\subsection{first subsetion of the third section}

\lipsum[1-3]



\subsection{second subsetion of the third section}

\lipsum[1-3]
\subsection{third subsetion of the third section}
\lipsum[1-11]






\end{document}

However, there is a problem with the header of the ToC and on page 6, we can see that the header is adequate regarding the section, but not for the subsection as it displays the third subsection of the first section ! It should be,

top left= section two

top middle= the page

top right=blank
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Kartik Apr 17 '14 at 12:30
  • Well, it is because the only 'mark' it has (and which is stored for use) is from the third subsection. Try adding a \subsectionmark{} right before your \section{second section}. By the way, all the "mark" stuff is just difficult unless your headers and footers are relatively static... – jon Apr 17 '14 at 15:02
3

My earlier comment only helped a bit. This is mainly because of your defined pagestyle, but also because \subsectionmark{} will automatically 'step' the counter.

This is what I would do:

  1. Add an extra page style for when there are pages with sections and no subsections; viz,

    \newpagestyle{nosubsec}{%
      \setfoot
        {\toptitlemarks Top is \thesubsection}%
        {}%
        {\bottitlemarks Bot is \thesubsection}%
      \sethead
        {\firstextramarks{section}\thesection---\sectiontitle}%
        {}%
        {\thepage}%
    }
    
  2. Patch your \section and \subsection commands to use them automatically. That is, make \section emit the \pagestyle{nosubsec} and then make \subsection emit \pagestyle{funny}:

    \usepackage{etoolbox}
    \pretocmd{\section}{\pagestyle{nosubsec}}{}{}
    \pretocmd{\subsection}{\pagestyle{funny}}{}{}
    

Your example document would then look like this:

\documentclass[twoside, a4paper, 11pt]{article}
\usepackage{etoolbox}
\usepackage[topmarks, extramarks]{titleps}
\settitlemarks*{section,subsection}

\newpagestyle{funny}{%
  \setfoot
    {\toptitlemarks Top is \thesubsection}%
    {\firsttitlemarks First is \thesubsection}%
    {\bottitlemarks Bot is \thesubsection}%
  \sethead
    {\firstextramarks{section}\thesection---\sectiontitle}%
    {\firstextramarks{subsection}\thesubsection---\subsectiontitle}%
    {\thepage}%
}
\pagestyle{funny}

\newpagestyle{nosubsec}{%
  \setfoot
    {\toptitlemarks Top is \thesubsection}%
    {}%
    {\bottitlemarks Bot is \thesubsection}%
  \sethead
    {\firstextramarks{section}\thesection---\sectiontitle}%
    {}%
    {\thepage}%
}

\pretocmd{\section}{\pagestyle{nosubsec}}{}{}
\pretocmd{\subsection}{\pagestyle{funny}}{}{}

\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\tableofcontents

\newpage

\section{first section}

\lipsum[1-3]
\subsection{first subsetion of the first section}
\lipsum[1-3]
\subsection{second subsetion of the first section}

\lipsum[1-3]
\subsection{third subsetion of the first section}
\lipsum[1-11]

\section{second section}
\lipsum[1-11]
\subsection{first subsetion of the second section}
\lipsum[1-3]

\subsection{second subsetion of the second section}

\lipsum[1-11]
\subsection{third subsetion of the second section}
\lipsum[1-11]


\section{thirs section}
%\lipsum[1-3]
\subsection{first subsetion of the third section}

\lipsum[1-3]

\subsection{second subsetion of the third section}

\lipsum[1-3]
\subsection{third subsetion of the third section}
\lipsum[1-11]

\end{document}

As I said earlier, though, the whole 'mark' system is a tricky business and it can be relatively easy to fool LaTeX into doing something you don't want...

  • I loose my account. The output is beautiful and very smart! – user50260 Apr 21 '14 at 8:48
  • @Phillip: You should contact the SE staff if you have account problems. – Werner Apr 21 '14 at 13:59

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.