Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

I don't believe that you get page breaks after subsection normally. What documentclass are you using? Cascabel Jul 30, 2009 at 20:24 Could you post your header (everything until the \begin{document}) so we can tell what's going wrong? Gerald Senarclens de Grancy Jul 30, 2009 at 20:26

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

My database project needs Planning document the "Building" document to show how to set up the system. They are sections in my LaTeX -file. Léo Léopold Hertz 준영 Aug 1, 2009 at 12:26 I can think of a stack of reasons why to put subsections in different files. The first that comes to mind, is having a CV with different levels of detail, depending on the target and/or job application. Once can easily chop bits out or put bits in, with a single '%' symbol. Nicholas Hamilton Dec 27, 2012 at 7:46 It's been a while since I wrote this answer, but I believe that parenthetical was meant to be sarcastic :) Will Robertson Dec 31, 2012 at 1:25 Another reason for cropping sections into different files: Consider writing exercise sheets always having a maketitle in the beginning but including always one exercise sheet only on the printout. I myself wouldn't consider every exercise sheet a chapter itself, especially since more exercise sheets refer to a single chapter in a lecture. The includeonly serves as counting the exercise sheets like sheet 1 with exercises (1.1-1.4), sheet 2 with exercises (2.1-2.3) and so on. C-star-W-star Oct 30, 2016 at 11:20

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

Thanks! This answer works well when you have multiple includes plus References and you don't want a new page for them. Just make a group of the last include one and the bibliography part, and no longer a clearpage. – Manuel Ferreria May 7, 2012 at 14:12 Manuel is right: you can use the \begingroup\let\clearpage\relax ...\endgroup trick wherever you like---stop pagebreaks between particular sections or parts, if you want the bibliography to be on on the same page as your text, etc. – John Aug 28, 2012 at 5:15 This solution appears to have caused some problems for me with references. In an included file which contained two enumerated lists, references to the items of the second list did not work. I have no idea why this should be, but switching to newclude fixed the problem. – Mike Shulman Dec 10, 2012 at 3:26 I recommend against using this method; it will create more problems than it solves (assuming it solves some problem in the first place): see tex.stackexchange.com/a/185237/4427 – egreg Jun 17, 2014 at 8:55

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
\newif\ifdraft\draftfalse
\ifdraft
  \include{...}
\ifdraft
  \include{file}
\else
  \input{file}

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.

Can you please give an example how you compile only one section of a very long working paper? I have used these methods of the following answer in pagesel about \discardpagesfromhere and \keeppagesfromhere. They are little overlapping each other so I am willing to learn if you can handle this draft management better. tex.stackexchange.com/a/267555/13173 – Léo Léopold Hertz 준영 Feb 24, 2016 at 9:00 If I understand it correclty, pagesel is to achieve more than includeonly by allowing fine control which pages are to be included in a final build. Include has a much smaller scope, of including sourcecode in a way that can be switched on and off. – gschenk Mar 1, 2016 at 1:35 \endgroup

The first \cleardoublepage ensures that your chapter ends up on an odd page for 2-sided.

The \let\clearpage\relax disables clearpage inserted by \include

The \begingroup \endgroup makes sure that the scope is just that include.

This is not the best advice. Why would you want to use \include{...] for a job when \input{...} is the actual command which is intendet for these situations? – Florian R. Klein Nov 5, 2013 at 11:41 This answer does not seem to answer the question at all. (Even though it is otherwise a useful advice, with a good reference.) – jciloa May 15, 2017 at 13:37

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.