Question

My LaTeX makes me pagebreaks after each subsection because my subsections are in separate files. I use the command \include{file} which adds a pagebreak after the use of it.

I would like to have no pagebreak caused by the use of \include{file}.

How can you no pagebreak after the use of include -command?

Was it helpful?

Solution

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.

OTHER TIPS

\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.)

Thank you, Cambridge!

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top