Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My document has a table of content in it. As i found out, after inserting one (\tableofcontents) LaTeX does a \clearpage by default.

A method to ignore \clearpage is the command \let\clearpage\relax, witch ignores it till the end of the document. Although i have no other command in my doc, my last page got erased. So i want to reactive \clearpage right after the toc was generated.

I am searching for something like:

\let\clearpage\relax
\tableofcontents
\*reactive it*

One try to do it with \begingroup failed.

\begingroup
\let\clearpage\relax
\tableofcontents
\endgroup

Any ideas?

share|improve this question
4  
the group version you have should have worked –  David Carlisle May 8 at 17:46
    
Any idea why it did not? –  Gary Klasen May 8 at 17:47
5  
Given your extensive test case and minimal working example:-) ? no idea at all. –  David Carlisle May 8 at 17:51
2  
@DavidCarlisle: I am afraid, but using a minimally possible example (class book, just a dummy chapter and grouping as the OP proposed) -- it really fails :-( –  Christian Hupfer May 8 at 17:54
    
@ChristianHupfer "fails" meaning what? This puts aaa th etable of contents and bbb on the same page: \documentclass{book} \begin{document} aaa aaaaaaaaaaaaaaaaa \begingroup \let\clearpage\relax \tableofcontents \endgroup bbb bbbbbbbbbbbbbbbb \chapter{xx} 111 \chapter{yy} 222 \end{document} –  David Carlisle May 8 at 18:04

2 Answers 2

up vote 5 down vote accepted

At least with the document class book, quick testing suggests that \tableofcontents doesn't insert a \clearpage, but \chapter does. Thus, you have to put your group with \let\clearpage\relax around the first \chapter command (or whatever you have that's similar) after your \tableofcontents. The following example, for instance, typesets on one page:

\documentclass{book}

\begin{document}

\tableofcontents

\begingroup
\let\clearpage\relax
\chapter{Hello, world!}
\endgroup
And goodbye.

\end{document}

The above document rendering on one page (without the page number).


The old answer, which answers the asked question but doesn't solve the problem (and anyway, you should usually use \begingroup\endgroup instead).

You can save and restore \clearpage:

\let\oldclearpage\clearpage
\let\clearpage\relax
\tableofcontents
\let\clearpage\oldclearpage

\let just defines a command to be a duplicate of an existing one, so:

  1. \let\oldclearpage\clearpage makes \oldclearpage equivalent to \clearpage.
  2. \let\clearpage\relax makes \clearpage equivalent to \relax, which is a do-nothing command.
  3. \tableofcontents runs, with its \clearpages doing nothing.
  4. Finally, \let\clearpage\oldclearpage makes \clearpage equivalent to \oldclearpage, which is equivalent to the original \clearpage.
share|improve this answer
    
I dont know why, but this did not work... –  Gary Klasen May 8 at 17:47
    
@GaryKlasen: I should have realized that, since your \begingroup\endgroup version should have worked. Perhaps some command after the \tableofcontents is the one issuing the \clearpage – have you tried making the group enclose more commands? –  Antal S-Z May 8 at 17:49
    
@AntalS-Z: I had the same idea you and Przemyslaw had, but if there is no restore to the old \clearpage command, a call to eventuall second chapters fails... –  Christian Hupfer May 8 at 17:51
    
does including external .tex-data causing one? –  Gary Klasen May 8 at 17:52
    
Okay, solved. Just followed your instructions, but used \let\clearpage\oldclearpage a lot later. –  Gary Klasen May 8 at 18:01
\let\standardclearpage\clearpage
\let\clearpage\relax
\tableofcontents
%\*reactive it*
\let\clearpage\standardclearpage
share|improve this answer
1  
I'm afraid Antal S-Z got there first, with a more detailed explanation. –  Jubobs May 8 at 17:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.