2

I'm new in LaTeX and trying to help my friend to fix her document. I use Texmaker 4.1.1. The LaTeX code of her document is as follows

Main Document: (Main Document.tex)

\documentclass[12pt,a4paper,oneside]{book}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{xcolor}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{subfigure}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{array,tabularx}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{enumitem}
\usepackage{eucal}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{appendix}
\usepackage{rotating}

\onehalfspacing
\parindent 1cm
\parskip 0.3cm
\topmargin 0cm \oddsidemargin 1cm \evensidemargin 0.5cm \textwidth 15cm \textheight 22cm
\newtheorem{dfn}{Definisi}[section]
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{remark}[theorem]{Remark}

\def\R{\mathbb{ R}}
\def\S{\mathbb{ S}}
\def\I{\mathbb{ I}}

\pagenumbering{roman}


\title{Taekwondo}
\makeindex
\date{}
\begin{document}
\renewcommand{\figurename}{Gambar}
\newcommand{\cchapter}[1]{\chapter[#1]{\centering #1}}
\renewcommand{\chaptername}{\huge CHAPTER}
\frontmatter
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents \addcontentsline{toc}{chapter}{Table of Contents}
\fancyhead[L]{\textsl{Table of Contents}}
\fancyhead[R]{}
\fancyfoot[C]{\thepage}
\renewcommand\listfigurename{Table of Figures}
\listoffigures \addcontentsline{toc}{chapter}{Table of Figures}
\fancyhead[L]{\textsl{Table of Figures}}
\fancyhead[R]{}
\fancyfoot[C]{\thepage}
\renewcommand{\bibname}{References}
\mainmatter
\include{Chapter2}
\end{document}

Chapter 2: (Chapter2.tex)

\chapter{{Theory}}

\pagestyle{fancy}
\fancyhead[L]{\textsl{Chapter 2 : Theory }}
\fancyhead[R]{}

\section{Taekwondo}
\begin{document}
List of protectors
\begin{enumerate}
\item[1.] \textit{Body protector}.
\item[2.] \textit{Head guard}.
\item[3.] \textit{Forearm guard}.
\item[4.] \textit{Hand protector}.
\item[5.] \textit{Shin guard}.
\item[6.] \textit{Groin guard}.
\item[7.] \textit{Mouth guard}.
\end{enumerate}
\begin{figure}
\centering
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{dobok.jpg}
  \caption{\textit{dobok}}
  \label{fig:dobok}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{equipment.jpg}
  \caption{Taekwondoin's Protector}
  \label{fig:peralatan}
\end{subfigure}
\caption{Taekwondo}
\label{fig:atribut}
\end{figure}
\end{document}

After compiling, I received the following error messages: enter image description here The error occurred when I tried to put code for setting figure side by side. I can't figure out the problem.

  • don't use begin{document} \end{document} in chapter2.tex – touhami Jul 30 '15 at 5:29
  • @touhami Thanks for the suggestion. I've deleted the \begin{document}...\end{document} code as suggested but I still received error message in the figure setting. What is my mistake now? – Venus Jul 30 '15 at 5:50
2

The document environment should only be declared once in your document. As such, main.tex should have the format

\documentclass[..]{...}
% <preamble>
\begin{document}
% <body>
\end{document}

and never have a

\begin{document}
% <body>
\end{document}

inside other .tex files you \input or \include.

Your error is replicated in the following minimal example:

\documentclass{article}
\begin{document}% Outer document environment begin
\begin{document}% Inner document environment begin
\end{document}% Inner document environment end
\end{document}% Outer document environment end

The second (inner) document environment - \begin{document} - causes the

LaTeX error: Can only be used in the preamble.

  • I've deleted the \begin{document}...\end{document} code as suggested but I still received error message in the figure setting. What is my mistake now? +1 anyway – Venus Jul 30 '15 at 5:48
  • 1
    @Venus: Remove the subfigure package from your preamble; subcaption already provides this functionality (in a far superior form). Moreover, subfigure is deprecated. – Werner Jul 30 '15 at 5:53
  • Thanks. It perfectly works. Can I ask you one thing. Why when I edited the code and ran it, the pdf output still load the previous version (before editing). I've edited many times but my editing didn't show up in the pdf output. – Venus Jul 30 '15 at 6:09
  • @Venus: That shouldn't happen, unless you didn't save the edits. – Werner Jul 30 '15 at 6:11
  • I did save it but still ... Is there a bug in my tex compiler? – Venus Jul 30 '15 at 6:30

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.