0

I asked a question about chapter/section marking in headers in a previous question, and got very helpful feedback from @Werner and @cfr. I discovered another problem when I implemented their suggestions, but I think seeking a solution to it warrants another question.

I'm new to this site, so please forgive me if I should have kept it in the comments of their answers.

I was trying to add marking that's \thechapter.\thesection, where \thesection is always the first new mark of the page on even pages, and the last mark of the page on odd pages. This works great in the example code, but when I apply it to the actual document it fails.

After reading logs and tinkering, I found out this happens whenever I use \tableofcontents in the document. When I remove \tableofcontents it works properly. The first page of random chapters won't show any chapter marks at all, only a header line, when I use \tableofcontents.

Here's the example code (comment/uncomment the \tableofcontents line and you'll see what I mean):

\documentclass[twoside,openany]{book}
\usepackage{lipsum}
\usepackage[pagestyles]{titlesec} %i usepackage the package this way instead of {titleps} because I use both titleps and titlesec in the actual document, and the manual says i need to include titleps this way if I use both.

\renewpagestyle{plain}{
    \sethead[\firsttitlemarks\bfseries\ifnum\value{section}=0 \thechapter\else\thesection\fi][][]% even-left | even-center | even-right
    {}{}{\bottitlemarks\bfseries\ifnum\value{section}=0 \thechapter\else\thesection\fi}% odd-left | odd-center | odd-right
    \setfoot[\thepage][][]% even-left | even-center | even-right
    {}{}{\thepage}% odd-left | odd-center | odd-right
    \setheadrule{0.4pt}
}
\pagestyle{plain}

\begin{document}

\tableofcontents

\chapter{Header Test CH1}
    \section{Sec1}
    \lipsum[1]
    \section{Sec2}
    \lipsum[3-4]
    \section{Sec3}
    \lipsum[5]
    \section{Sec4}
    \lipsum[7]
\chapter{Header Test CH2}
    \section{Sec1}
    \lipsum[2]
    \section{Sec2}
    \lipsum[6]
    \section{Sec3}
    \lipsum[8-9]
    \section{Sec4}
    \lipsum[10]
\chapter{Header Test CH3}
\lipsum[1-4]
\chapter{Header Test CH4}
    \section{Sec1}
    \lipsum[2]
    \section{Sec2}
    \lipsum[6]
    \section{Sec3}
    \lipsum[8-9]
    \section{Sec4}
    \lipsum[10]
\chapter{Header Test CH5}
    \section{Sec1}
    \lipsum[10]
    \lipsum[1-4]
    \lipsum[1-4]
    \lipsum[1-4]
    \lipsum[1-4]
\chapter{Header Test CH6}
    \section{Sec2}
    \lipsum[2]
    \section{Sec3}
    \lipsum[6]
    \section{Sec4}
    \lipsum[8-9]
    \section{Sec5}
    \lipsum[10]
\end{document}

Is this a known issue with a workaround? Is there something wrong with my use of the package? Is there a way this can be fixed?

In the actual document, I also get an 'Undefined control sequence' error on the line that \tableofcontents is called. When I comment out the titleps lines and replace them with the fancyhdr lines, this error goes away. This might be a question for another post, but I figured I'd say it here now in case there's an obvious reason for it.

1 Answer 1

1

See my edited answer to your other question:

\documentclass[twoside,openany]{book}
\usepackage{lipsum}
\usepackage[pagestyles]{titlesec}
\renewpagestyle{plain}{
  \sethead[\firsttitlemarks\bfseries\ifthesection{\thesection}{\ifthechapter{\thechapter}{\chaptertitle}}][][]% even-left | even-center | even-right
  {}{}{\bottitlemarks\bfseries\ifthesection{\thesection}{\ifthechapter{\thechapter}{\chaptertitle}}}% odd-left | odd-center | odd-right
  \setfoot[\thepage][][]% even-left | even-center | even-right
  {}{}{\thepage}% odd-left | odd-center | odd-right
  \setheadrule{0.4pt}
}
\pagestyle{plain}

\begin{document}

  \tableofcontents

  \chapter{Header Test}
  \section{Sec1}
  \lipsum[1]
  \section{Sec2}
  \lipsum[3-4]
  \section{Sec3}
  \lipsum[5]
  \section{Sec4}
  \lipsum[7]
  \chapter{New Chapter}
  \section{Sec5}
  \lipsum[2]
  \section{Sec6}
  \lipsum[6]
  \section{Sec7}
  \lipsum[8-9]
  \section{Sec8}
  \lipsum[10]
  \chapter{GAH}
  \lipsum[1-4]
  \chapter{New Chapter AAAA}
  \section{Sec5}
  \lipsum[2]
  \section{Sec6}
  \lipsum[6]
  \section{Sec7}
  \lipsum[8-9]
  \section{Sec8}
  \lipsum[10]
  \chapter{GAH1}
  \section{Sec8}
  \lipsum[10]
  \lipsum[1-4]
  \lipsum[1-4]
  \lipsum[1-4]
  \lipsum[1-4]
  \chapter{New CHAPTER AAAAA}
  \section{Sec5}
  \lipsum[2]
  \section{Sec6}
  \lipsum[6]
  \section{Sec7}
  \lipsum[8-9]
  \section{Sec8}
  \lipsum[10]
\end{document}

You must log in to answer this question.

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