Skip to content

Wrong page number in table of contents and wrong page header #50

@cabohah

Description

@cabohah

The order of \addcontentsline, \@vstypeptitle, \poemtitlemark in \@vsptitle can result in wrong page number in the table of contents and a wrong page header.

\documentclass[12pt]{article}
    \usepackage{verse}
    \usepackage{fancyhdr} 
        \pagestyle{fancy}
        \fancyhf{}
        \fancyhead[L]{\leftmark} %% poem title automatically here
        \fancyhead[R]{p.~\thepage}
\renewcommand{\poemtitlemark}[1]{\markboth{#1}{#1}}

\newcounter{mypoemline}
\makeatletter
\newcommand*{\dummypoem}[1][4]{%
  \setcounter{mypoemline}{0}%
  \@whilenum \value{mypoemline}<#1 \do{This is is dummy
    poem\\\stepcounter{mypoemline}}
}
\makeatother

\begin{document}

\tableofcontents
\newpage

\begin{verse}

\poemtitle{Invictus}
by William Ernest Henley

Out of the night that covers me, \\
\vin Black as the pit from pole to pole, \\
I thank whatever gods may be \\
\vin For my unconquerable soul. \\!
\ldots

\dummypoem[25]

\poemtitle{Test}

\dummypoem

\end{verse}

\end{document}

results in

Incorrect page number in ToC and page header on page 3

I suggest to change the definition into

\def\@vsptitle[#1]#2{%
  \@nameuse{phantomsection}%
  \@vstypeptitle{#2}%
  \addcontentsline{toc}{\poemtoc}{#1}%
  \poemtitlemark{#1}%
   \@afterheading
}

With this the page number in the table of contents and the page header of the third page is correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions