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}
1
  • Please show more of your code
    – user31729
    Commented Sep 15, 2015 at 20:42

1 Answer 1

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

5
  • 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. Commented Sep 16, 2015 at 12:49
  • Thats strange, since I got your wanted result. Have you compiled it twice? Or could you provide a complete MWE?
    – manthano
    Commented Sep 16, 2015 at 13:26
  • I did. I also tried removing all intermediate files. I'll update my question with a MWE. Commented Sep 17, 2015 at 21:38
  • Thanks for your update, but this produces empty pages, which I would like to omit. Commented Sep 18, 2015 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? Commented Sep 18, 2015 at 12:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .
https://tex.stackexchange.com/questions/267732/adding-a-pseudo-chapter-with-page-number
tex.stackexchange.com
CC-MAIN-2024-26
148583
application/http; msgtype=response
sha1:HTIIFICS2FS2D6JGLQER3N2NGDISRG2F
<urn:uuid:804380bd-b8b5-41ed-a3a1-8fb647f96af9>
2024-06-24T15:59:05Z
104.18.43.226
text/html
sha1:X2WRMT6J4NR6IN4ZAA3G7YVWOYUORDN7
<urn:uuid:39baf7f2-a4a8-433d-ae09-62059eae4351>
https://tex.stackexchange.com/questions/267732/adding-a-pseudo-chapter-with-page-number
response
<urn:uuid:a1fd5def-f9a6-4906-bd55-b95977734d4d>
isPartOf: CC-MAIN-2024-26
publisher: Common Crawl
description: Wide crawl of the web for June 2024
operator: Common Crawl Admin (info@commoncrawl.org)
hostname: ip-10-67-67-161
software: Apache Nutch 1.20 (modified, https://github.com/commoncrawl/nutch/)
robots: checked via crawler-commons 1.5-SNAPSHOT (https://github.com/crawler-commons/crawler-commons)
format: WARC File Format 1.1
conformsTo: https://iipc.github.io/warc-specifications/specifications/warc-format/warc-1.1/