Search code examples
latexpage-break

How to have no pagebreak after \include in LaTeX


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?


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.