I was writing my masters' thesis using Latex and have written 4 chapters in 4 different .tex files. Now I wish to combine all these chapters into a single .pdf file. For this I wrote a main .tex file in which I included the 4 tex files using \include statement. However, everytime I run the main tex file, I see an error message :

Message : ! Latex error ! Can be used only in preamble.

What I wrote in the main tex file was the following :

\usepackage{varioref}                                                               %   when using \vref the page the figure is on is printed
\usepackage[margin=10pt,font=small,labelfont=bf]{caption}                          %   enables caption adjustments
\usepackage{url}                                                                    %   makes nice url's
\usepackage[a4paper, left=3cm,right=3cm,top=4cm,bottom=4cm]{geometry}
\usepackage{bbm}                                                                    %   enables \mathbbm
\usepackage{lscape}                                                                 %   enables landscape tables
%\usepackage{lettrine}                                                               %   enables dropcaps ('miniaturen')


\include{Chapter1_Introduction_Final}       % Names of my tex files           

If I compile each .tex file individually , then I get separate .pdf files. However, I want to generate a single .pdf file consisting of all 4 chapters. I would be obliged for the assistance.


It appears that you have a separate preamble in each of your sub files. Latex can only handle one preamble in the master document. You could now either delete/comment the preamble in the chapter-files, or you can use the combination of the standalone package-class combination.

In your chapter files you can use the documentclass \documentclass{standalone} and in your master file you load the \usepackage{standalone}.

This should then remove the preambles from your chapter-files. This way you can still compile the individual files, or you can compile the master document.

| improve this answer | |

To keep your source clean, I would recommend to only have the preamble in the master document, but compile a part of your document by means of \includeonly{} or \excludeonly{}. For \excludeonly, you need to load the underlying package by \usepackage{excludeonly}. The advantage of this approach is that the chapter and page numbers will be like in the complete document, whereas compiling single chapters fully standalone will result in multiple chapters 1.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.