I have two documents A and B. Both of them are separate documents. But document A also has to include document B.

Now if I use \include{B} i get the following error:

! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.

l.1 \documentclass

So how can I force to include document B with the "style" and "template" of document A?


5 Answers 5


Cut the content (the part between \begin{document}...\end{document} of B.tex into a new file B-content.tex.

Change B.tex to be:

% your preamble here

Then put \include{B-content} into A.tex.


You can use the standalone, docmute or subfiles package to make LaTeX ignore the second preamble.

Simply load the standalone package in the main file and \input or \include the document. This is a good way if the to-be-included documents just holds a picture which should also be compiled standalone. In this case having main files for every picture file would be annoying.

% A.tex
% your preamble here
% ...
\input{B}% or \include
% ...
% B.tex (for normal text)
% your preamble here
% your B content here

or if B should hold some diagram only (note the different class):

% B.tex
% your preamble here
% your diagram code here
  • 2
    standalone looks like a very nice idea. I'll have to keep it in mind. Feb 17, 2011 at 18:56
  • 5
    @Matthew: Thanks, I wrote it because I have a lot of TikZ pictures and I hated the long re-compiling runs during the creation of the more complicated ones when they are inside a document. They are used multiple times across my papers, presentations and thesis anyway. Having extra main files for each was to cumbersome for me. Have a look at the options: you can collect all the "sub-preambles" automatically! Feb 17, 2011 at 19:02
  • @Martin 1. Is B-content in your code a typo for B? 2. I am unable to extract your simple examples here from your package documentation. I would recommend clarifying your package documentation accordingly. 3. I cannot specify a path with \include, whereas it works fine with \input. Is that behavior intentional?
    – Sverre
    Oct 31, 2013 at 15:17
  • @Sverre: 1. Yes, that was wrong. I corrected it above. 2. I'm planning to rework the manual already. 3. \include does a lot more than \input and uses the given filename several times for e.g. creating an .aux file. Due to security reasons TeX doesn't allow .. in relative file paths and not absolute file paths at all. I guess one of these two things cause trouble in your case. Nov 1, 2013 at 9:26
  • @Martin: What do you mean by ..? And "TeX doesn't allow absolute file paths at all"? I use absolute file paths for many things in my preamble.
    – Sverre
    Nov 1, 2013 at 10:54

You can try using the combine class but be warned this is not what LaTeX is designed for!

An alternative that I haven't tried is to use the newclude package and write


This latter approach assumes that all of the packages, etc., you need are loaded by the first file.


Here is probably a non-conventional way of doing this. I was trying to combine a few files while still hoping to be able to compile each file individually. I used the catchfilebetweentags package to get it done.

Let says I have file1.tex and file2.tex, which I only want to include the part lies between \begin{document} and \end{document}. I labelled it with tag name of document.

In file1.tex and file2.tex,


For clarity, %<*tagname> and %</tagname> is the way to tag the content to be used in the catchfilebetweentags package.

So in my main.tex, I want to include the content in file1.tex and file2.tex.

<remember to add preambles that are needed>

    \ExecuteMetaData [file1.tex] {document}
    \ExecuteMetaData [file2.tex] {document}

Voila! Here you go! You can still compile each of the file individually.

There is one problem with cathcfilebetweentags as mentioned in \input only part of a file using catchfilebetweentags package. The line break is not recognised when you are having an empty line to indicate line break.

Thank to egreg for providing the solution here. Basically you can just add this to your preamble.

      %\endlinechar\m@ne % <- this is the guilty party
      \makeatletter #2%
}% \CatchFBT@Final

If you desire more explanation on this, please check out on \input only part of a file using catchfilebetweentags package.


As far as I know, include simply inserts the text wherever it is used. So you can't have a preamble in document B. At a quick glance, I would create a wrapper document C and use \include{B} in both after editing B so that it only contains your desired output text

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .