2

I want to manually add a chapter to the ToC and add a specific number to the page counter. This is meant for adding to my document a number of papers, which are printed out elsewhere and which I cannot add into the LaTeX file.

I tried this,

\newcommand{\pseudochapter}[2][0]
{
    \addtocounter{chapter}{1}
    \addtocontents{toc}{\protect\contentsline
          {chapter}{\protect\numberline {\thechapter}#2}{\thepage}{}}
    \clearpage
    \addtocounter{page}{#1}
}

However, invoking this,

\pseudochapter[3]{Pseudo Contents}
\chapter{Real Contents}

leads to output in the ToC like this,

Pseudo Contents ... 4
Real Contents ..... 4

What I expected (or wished) to find, is this,

Pseudo Contents ... 1
Real Contents ..... 4

This

\chapter{Real Contents}
\pseudochapter[3]{Pseudo Contents}
\chapter{Real Contents}

gives me

Real Contents ..... 1
Pseudo Contents ... 1
Real Contents ..... 5

when expecting

Real Contents ..... 1
Pseudo Contents ... 2
Real Contents ..... 5

I'm using KOMA class scrbook.

Here is a MWE:

\documentclass[openany]{scrbook}

\newcommand{\pseudochapter}[2][0]
{
    \addtocounter{chapter}{1}
    \addtocontents{toc}{\protect\contentsline
          {chapter}{\protect\numberline {\thechapter}#2}{\thepage}{}}
    \clearpage
    \addtocounter{page}{#1}
}

\begin{document}
    \tableofcontents\thispagestyle{empty}\clearpage
    \setcounter{page}{1}
    \chapter{Real Contents}
    \pseudochapter[3]{Pseudo Contents}
    \chapter{Real Contents}
\end{document}
  • Please show more of your code – user31729 Sep 15 '15 at 20:42
3

You nearly got it right

\newcommand{\pseudochapter}[2][0]
{
    \addtocounter{chapter}{1}
    \addtocontents{toc}{\protect\contentsline
          {chapter}{\protect\numberline {\thechapter}#2}{\thepage}{}}
    \clearpage
    \addtocounter{page}{#1}
}

You have to move the \clearpage after the \addtocontents, so that the \addtocounter won't affect the pseudo chapter.

EDIT:

To solve your new problem you can use

\newcommand{\pseudochapter}[2][0]
{
    \clearpage\phantom{empty}
    \addtocounter{chapter}{1}
    \addtocontents{toc}{\protect\contentsline
        {chapter}{\protect\numberline {\thechapter}#2}{\thepage}{}}
    \clearpage
    \addtocounter{page}{#1}
}

You need \phantom for the second \clearpage to work, since yor the page after the first stays clear. This command provides empty pages, so you can't use it in the middle of the first chapter (What I don't think you want).

EDIT #2:

\newcommand{\pseudochapter}[2][0]
{
    \newcounter{tmppage}
    \setcounter{tmppage}{\thepage}
    \stepcounter{tmppage}

    \addtocounter{chapter}{1}
    \addtocontents{toc}{\protect\contentsline
          {chapter}{\protect\numberline {\thechapter}#2}{\thetmppage}{}}
    \clearpage
    \addtocounter{page}{#1}
}

This way no empty pages are created before the command. It's not the most elegant form, but the first i could thought of. If I get a better idea, I will post it here

  • I must admit, this doesn't work, either. It gives me the same output. I'll update my questions with the solution you provided with further testing. – PhilippVerpoort Sep 16 '15 at 12:49
  • Thats strange, since I got your wanted result. Have you compiled it twice? Or could you provide a complete MWE? – manthano Sep 16 '15 at 13:26
  • I did. I also tried removing all intermediate files. I'll update my question with a MWE. – PhilippVerpoort Sep 17 '15 at 21:38
  • Thanks for your update, but this produces empty pages, which I would like to omit. – PhilippVerpoort Sep 18 '15 at 10:25
  • Great. That does the job. It may look like an ugly workaround, but I think it is the simplest and most obvious way to do this. However, you forgot the \addtocounter{chapter}{1} cmd. You wanna add this? – PhilippVerpoort Sep 18 '15 at 12:28

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.