2

I am writing thesis in LaTeX and I am beginner in LaTeX. I read about combining files into main file, but it didn't help me much and my problem persists. I am giving minimal code what I am trying to do. Please help me with this problem. Compiler doesn't compile files when it encounters table or figure code and it seems that \usepackage is necessary for individual files as well.

%MAIN.tex

\documentclass[a4paper,12pt,oneside,openright,draft]{book}

\input{preamble}

\begin{document}

\frontmatter

\tableofcontents

\listoffigures

\listoftables

\mainmatter

\include{Chapter1}

\include{Chapter2}

\end{document}

%% end of MAIN.tex-------------------------
%%preamble.tex

\usepackage{microtype}

\usepackage[demo]{graphicx}

\usepackage{index}

\usepackage{ctable}

\usepackage{tabls}

\newcommand{\head}[1]{\textbf{#1}}

%%end of preamble.tex-------------------------

%%starting chapter1.tex

\chapter{Main chapter}

\section{First section of the first chapter}

\subsection{subsec 1}

\subsubsection{subsubsec 1}

\subsubsection{subsubsec 2}

\subsection{subsec 2}

{\Large Here's figure} \\

\begin{figure}[h!]

\centering

        \includegraphics{test}

    \caption{test {\index {new figures}}}

    \label{fig:test1}

\end{figure}

%%end of chapter1.tex-------------------------

%%starting chapter2.tex

\chapter{Tables}

\begin{tabular}{cccc}

& \multicolumn{2}{c}{Input} & \multicolumn{1}{c}{Output}\\

& \head{A} & \head{B} & \head{C} \\

\cmidrule[1pt](l){1-3} \cmidrule[1pt](lr){4-4}

\multirow{3}{*}{Data} & 10 & 20 & 30\\

& 40 & 60 & 100\\

& 25 & 50 & 75\\

\bottomrule[1.5pt]

\vspace{2mm}

\caption{My table}

\end{tabular}

%end

Thanks for your suggestions. I modified my code, but still errors are there. I cannot figure out where I am going wrong. When I compile individual Chapter 2, there are no errors. But when I combine it to the main file, there is error

!missing \cr inserted

Main file:

\documentclass[a4paper,12pt,oneside,openright,draft]{book}
\input{preamble}
\begin{document}
\newcommand{\head}[1]{\textbf{#1}}
\frontmatter
\tableofcontents
\listoffigures
\listoftables

\mainmatter
\include{Chapter1}
\include{Chapter2}

\end{document}

Chapter 1

\chapter{Main chapter}
\section{First section of the first chapter}
\subsection{subsec 1}
\subsubsection{subsubsec 1}
\subsubsection{subsubsec 2}
\subsection{subsec 2}
{\Large Here's figure} \\

\begin{figure}[h!]
\centering
\includegraphics{test}
\caption{test}
\label{fig:test1}
\end{figure}

Chapter 2

\chapter{Tables}
    \begin{table}
\begin{tabular}{cccc}
& \multicolumn{2}{c}{Input} & \multicolumn{1}{c}{Output}\\
& \head{A} & \head{B} & \head{C} \\
\cmidrule[1pt](l){1-3} \cmidrule[1pt](lr){4-4}
\multirow{3}{*}{Data} & 10 & 20 & 30\\
& 40 & 60 & 100\\
& 25 & 50 & 75\\
\bottomrule[1.5pt]
\end{tabular}
\vspace{2mm}
\caption{My table}
David Carlisle
  • 757,742
  • I believe that the problem is on the tabular environment. Did you try to compile only it to look for some errors? – Sigur Jan 10 '13 at 01:15
  • 2
    Obviously this is not minimal code. Try to put together your code step by step and bit by bit next time and probably you'll find the error yourself. With a large chunk of code like this it's easy to assume something's wrong with X when actually it's Y and Z that are causing the problems (X being the includes and Y and Z being the indexing and the table in this case). – Christian Jan 10 '13 at 01:24
  • Your chapter 2 appears to be missing \end{table} at the end, and now \newcommand{\head}[1]{\textbf{#1}} appears in both your main document and your preamble. It is not clear what you are doing when you say "compile individual Chapter 2", and "combine it to the main file". When TeX reports an error, you should normally get a file and line number associated to help you find out where the problem lies. – cyberSingularity Jan 10 '13 at 07:36

1 Answers1

4

I don't think that your problems are due to external files but simply that the markup used doesn't match the packages.

I get an error about

! LaTeX Error: Index type `default' undefined.

unless I comment out index

You use \multirow but the multirow package isn't loaded the tabls package appears incomparible with your apparently correct header line in th etable in chapter 2 so I removed that

Then you have spacing and \caption within the tabular which is an error I moved them to a table environment.

this runs without error.

main and chapter1 as above then

preamble:

%preamble.tex

\usepackage{microtype}

\usepackage[demo]{graphicx}

%\usepackage{index}

\usepackage{ctable}

%\usepackage{tabls}

\usepackage{multirow}

\newcommand{\head}[1]{\textbf{#1}}

chapter2

%starting chapter2.tex

\chapter{Tables}

\begin{table}
\begin{tabular}{cccc}

& \multicolumn{2}{c}{Input} & \multicolumn{1}{c}{Output}\\
& \head{A} & \head{B} & \head{C} \\

\cmidrule[1pt](l){1-3} \cmidrule[1pt](lr){4-4}

\multirow{3}{*}{Data} & 10 & 20 & 30\\

& 40 & 60 & 100\\

& 25 & 50 & 75\\

\bottomrule[1.5pt]


\end{tabular}
\vspace{2mm}

\caption{My table}
\end{table}
%end
David Carlisle
  • 757,742