Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have no pagebreak after \include in LaTeX

People also ask

How do I stop a Pagebreak in LaTeX?

The \nopagebreak command prevents LaTeX form breaking the current page at the point of the command. With the optional argument, number, you can convert the \nopagebreak command from a demand to a request. The number must be a number from 0 to 4. The higher the number, the more insistent the request is.

How do you end a page in LaTeX?

10.2 \newpage LaTeX's page breaks are optimized so ordinarily you only use this command in a document body to polish the final version, or inside commands. While the commands \clearpage and \cleardoublepage also end the current page, in addition they clear pending floats (see \clearpage & \cleardoublepage ).

What does clear page do in LaTeX?

The \clearpage command ends the current page and causes all figures and tables that have so far appeared in the input to be printed.

What is \include in LaTeX?

LaTeX commands \includeonly and \include are used to design the chapter structure in a book or thesis. Chapters in progress appear in the \includeonly comma-separated list, in the preamble of the main LaTeX file.


\include always uses \clearpage, a not entirely sensible default. It is intended for entire chapters, not for subsections (why would you want subsections in separate files, anyway?).

You can fix it either by using \input{filename} or loading the newclude package and writing \include*{filename} instead.


You can stop pagebreaks caused by \include by placing \let\clearpage\relax before it. So,

\let\clearpage\relax
\include{file1}
\include{file2}
\include{file3}

would put the contents of the three files (and any subsequently included files) together without a pagebreak between them. If you want to stop relaxing the \clearpage command, then wrap the files to include without pagebreaks within a group like this:

\begingroup
\let\clearpage\relax
\include{file1}
\include{file2}
\endgroup
\include{file3}

This will stop a pagebreak between file1 and file2, but insert the normal pagebreak after file2. (Note: I do not know if this interferes with referencing and page numbering, though I imagine it should be OK.)


The newclude package suggested by Will Robertson is rather useful to avoid the clearpage. It appears, in order for \includeonly to work one has to call the package immediately after \documentclass{...}. In the complex environment of my dissertation I also ran into problems with broken references.

A good workaround, when includeonly is not needed for a final version, is to use includes only in the draft:

\newif\ifdraft\drafttrue

or

\newif\ifdraft\draftfalse

\ifdraft
  \include{...}
\fi

\ifdraft
  \include{file}
\else
  \input{file}
\fi

The first line can be easily appended by a makefile, to make draft or production version production make targets.

\includeonly{file1,file2,...} allows to specify a list of source files called with \include{file1} (where file1 is an example) that will show in the resulting document. The others will not show up, but are considered for counters, labels, tables of contents when the corresponding aux files are included.

In other words, by using include and includeonly one can keep the compile time short in a draft while having correct references. Further reading on Wikibooks.

@Will Robertson

\include is so useful because it allows through \includeonly{...} to build only needed sections. While working on longer text it can make quite a difference in compile time to include only a section of a lengthy chapter. It is also invaluably useful as one doesn't have to page through a long draft while working at one point. Lastly, smaller files of source code are easier to handle in version management, e.g. git.


Thank you, Cambridge!

use \include instead of \input, and use the \includeonly command to select sections to process