0

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 :

\documentclass[10pt]{thesis}
%\usepackage{pgf}
\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{amsmath}
\usepackage{amsfonts}
\usepackage{subfigure}
\usepackage{array}
\usepackage{url}                                                                    %   makes nice url's
\usepackage[a4paper, left=3cm,right=3cm,top=4cm,bottom=4cm]{geometry}
%\usepackage{mathcomp}
%\usepackage{mathptmx}
\usepackage{graphicx,color}
\usepackage[english]{babel}
\usepackage{bbm}                                                                    %   enables \mathbbm
\usepackage{lscape}                                                                 %   enables landscape tables
%\usepackage{lettrine}                                                               %   enables dropcaps ('miniaturen')
\usepackage{float}
\usepackage{caption}

%\usepackage{here}
%\usepackage{rotate}
%\usepackage{fancyhdr}
\usepackage{multirow}
\usepackage{picins}
\usepackage{a4}
\usepackage{braket}
\usepackage{cite} 

\begin{document}
\include{Chapter1_Introduction_Final}       % Names of my tex files           
\include{Chapter2_STIOS}                   
\include{Chapter3_FrequencyStabilization}                  
\include{Chapter4_VHDLperformance}                  
\end{document}

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.

1

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.

1

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.

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.