0

I'm using the class MasterDoctoralThesis that you can find here https://www.latextemplates.com/template/masters-doctoral-thesis.

This is my main:

\documentclass[
11pt, 
english, 
singlespacing,
headsepline
]{MastersDoctoralThesis} 

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 

\usepackage{mathpazo} 

\usepackage[backend=bibtex,style=authoryear,natbib=true]{biblatex} )

\addbibresource{example.bib} 

\usepackage[autostyle=true]{csquotes}

%----------------------------------------------------------------------------------------
%   MARGIN SETTINGS
%----------------------------------------------------------------------------------------

\geometry{
    paper=a4paper, 
    inner=2.5cm, 
    outer=3.8cm, 
    bindingoffset=.5cm, 
    top=1.5cm,
    bottom=1.5cm
}

%----------------------------------------------------------------------------------------
%   THESIS INFORMATION
%----------------------------------------------------------------------------------------

\thesistitle{Title Thesis} 
\supervisor{Prof. X \textsc{Y} \\ Dr. Z \textsc{W}}
\degree{Master of Science in  Electronic Engineering} 
\author{Name \textsc{Surname}}

\subject{Electronic Engineering} 
\keywords{} 
\university{{Università}} 
\department{{Department of Information Engineering, Electronics and Telecommunications}} 
\group{{Master of Science in Electronic Engineering}} 
\faculty{{Faculty of Information Engineering, Informatics and Statistics}} 

\AtBeginDocument{
\hypersetup{pdftitle=\ttitle} 
\hypersetup{pdfauthor=\authorname}
\hypersetup{pdfkeywords=\keywordnames} 
}

\begin{document}

\frontmatter 

\pagestyle{plain} 

%----------------------------------------------------------------------------------------
%   TITLE PAGE
%----------------------------------------------------------------------------------------

\begin{titlepage}

\begin{center}
\includegraphics[scale=1]{logo.jpg}
\end{center}

\begin{center}

\vspace*{.01\textheight}
\textsc{\Large Master Thesis}\\[1cm]

\HRule \\[0.4cm] 
{\huge \bfseries \ttitle\par}\vspace{0.4cm} 
\HRule \\[1.5cm] 

\begin{minipage}[t]{0.4\textwidth}
\begin{flushleft} \large
\emph{Author:}\\
\href{}{\authorname} 
\end{flushleft}
\end{minipage}
\begin{minipage}[t]{0.4\textwidth}
\begin{flushright} \large
\emph{Supervisor:} \\
{\supname} 
\end{flushright}
\end{minipage}\\[2cm]

\begin{center}
\includegraphics[scale=0.4]{logo2.jpg}\hfill\includegraphics[scale=0.5]{logo3.jpg}
\end{center}

\vspace*{1.5cm}

\groupname\\\deptname\\[1.5cm] 

\vfill

\rule{3cm}{1pt}\\
{\large \today}\\[4cm] 
%\includegraphics{Logo} 

\vfill
\end{center}
\end{titlepage}    
%----------------------------------------------------------------------------------------
%   QUOTATION PAGE
%----------------------------------------------------------------------------------------

\vspace*{0.2\textheight}

\begin{flushright}
\thispagestyle{empty}
\vspace*{5cm} 
\itshape\enquote{Something}\\[0.3cm]
\end{flushright}
\hfill Name
    %----------------------------------------------------------------------------------------
%   ABSTRACT PAGE
%----------------------------------------------------------------------------------------

\begin{abstract}
\addchaptertocentry{\abstractname} 
The Thesis Abstract is written here (and usually kept to just this page). The page is kept centered vertically so can expand into the blank space above the title too\ldots
\end{abstract}
    %----------------------------------------------------------------------------------------
%   ACKNOWLEDGEMENTS
%----------------------------------------------------------------------------------------

\begin{acknowledgements}
\addchaptertocentry{\acknowledgementname} 
The acknowledgments and the people to thank go here, don't forget to include your project advisor\ldots
\end{acknowledgements}
    %----------------------------------------------------------------------------------------
%   LIST OF CONTENTS/FIGURES/TABLES PAGES
%----------------------------------------------------------------------------------------

\tableofcontents 

\listoffigures 

\listoftables 
    %----------------------------------------------------------------------------------------
%   ABBREVIATIONS
%----------------------------------------------------------------------------------------

\begin{abbreviations}{ll} %

\textbf{LAH} & \textbf{L}ist \textbf{A}bbreviations \textbf{H}ere\\
\textbf{WSF} & \textbf{W}hat (it) \textbf{S}tands \textbf{F}or\\

\end{abbreviations}
    %----------------------------------------------------------------------------------------
%   PHYSICAL CONSTANTS/OTHER DEFINITIONS
%----------------------------------------------------------------------------------------

\begin{constants}{lr@{${}={}$}l}      
Speed of Light & $c_{0}$ & \SI{2.99792458e8}{\meter\per\second} (exact)\\   
\end{constants}
    %----------------------------------------------------------------------------------------
%   SYMBOLS
%----------------------------------------------------------------------------------------

\begin{symbols}{lll} 

$a$ & distance & \si{\meter} \\
$P$ & power & \si{\watt} (\si{\joule\per\second}) \\
%Symbol & Name & Unit \\

\addlinespace     
$\omega$ & angular frequency & \si{\radian} \\

\end{symbols}
    %----------------------------------------------------------------------------------------
%   DEDICATION
%----------------------------------------------------------------------------------------

\dedicatory{For my family} 
\end{document}  
    %----------------------------------------------------------------------------------------
%   THESIS CONTENT - CHAPTERS
%----------------------------------------------------------------------------------------

\mainmatter 

\pagestyle{thesis} 

\include{Chapters/Introduction}
%\include{Chapters/Chapter1}

And this is my first chapetr in which there is a figure:

% Chapter 1

\chapter{Titlte} % Main chapter title

\label{Chapter1} % For referencing the chapter elsewhere, use \ref{Chapter1} 

%----------------------------------------------------------------------------------------

% Define some commands to keep the formatting separated from the content 
%\newcommand{\keyword}[1]{\textbf{#1}}
%\newcommand{\tabhead}[1]{\textbf{#1}}
%\newcommand{\code}[1]{\texttt{#1}}
%\newcommand{\file}[1]{\texttt{\bfseries#1}}
%\newcommand{\option}[1]{\texttt{\itshape#1}}

%----------------------------------------------------------------------------------------
Introduction

\section{Layout}
Write here my text

\begin{center}
\includegraphics[scale=0.5]{Layout.jpg}
\caption{This is the caption of the figure}
\end{center}

The problem is that I was trying to add a caption to my figure, before doing it the main was compiling without problems, but as soon as I put \caption it returns me some errors. In particular in the main I have:

I can't write on file 'Chapters/Introduction.aux'\include{Chapters/Introduction}
Emergency stop \include{Chapters/Introduction}

Which I really can't understand since I haven't changed the Introduction.

And then in the Chapter1 I have this error:

Undefined control sequence \section

If I remove \caption everything returns to work well.

In addition, I would like to know if there is a way to automatically add the figure in the List of Figure.

Can someone help me, please? Thanks.

| improve this question | | | | |
  • 1
    You can't use \caption outside of a float (figure or table that is). Either use one of the floating environments (figure in this case), with \centering inside of it, or use \captionof{figure}{...} inside of your center environment. \captionof is provided by the packages capt-of or caption and by the KOMA-script classes (those starting with scr). – Skillmon likes topanswers.xyz Oct 24 '18 at 8:00
  • It doesn't matter whether you change the contents of a file, the .aux file is written on every run the file is included. The way you build your document seems wrong, as \section is almost certainly defined if you load a \documentclass, I guess that you tried to compile your chapter file on its own, which won't work. Also your \include of the chapter is after \end{document} which won't do anything. – Skillmon likes topanswers.xyz Oct 24 '18 at 8:05
  • If you're using a correct way to build your document and \include your chapter at the right spot (in between of \begin{document} and \end{document}) a \captionof{figure} or a \caption inside of a figure should be written to the correct list (the list of figures that is). – Skillmon likes topanswers.xyz Oct 24 '18 at 8:08
  • Thanks for your answer. I have understood what you were explaining abut the problem of the position on th \end{document}, but I'm not sure to have understood the problem of the figure. I modified my code putting \begin{center}[H] \centering \includegraphics[scale=0.5]{Layout.jpg} \caption{Write some caption here} \end{center} but it's still not working. I'm sorry but it's the first time I use latex. – XaBla Oct 24 '18 at 8:20
  • You have to use figure not center for a float with a caption. If you for some reason don't want to use a float, you can use \captionof. Correct code would be something like \begin{figure}\centering\includegraphics[<options>]{<image>}\caption{<caption text>}\end{figure}. – Skillmon likes topanswers.xyz Oct 24 '18 at 8:32
1

You can't use the \caption macro outside of floats (e.g. figure or table environments). For such use cases there is the capt-of package. With it you could use \captionof outside of said environments, so the following could be done with \usepackage{capt-of} in the preamble:

\begin{minipage}
  \centering
  \includegraphics{example-image-duck}
  \captionof{figure}{A friendly looking duck\label{fig:duck}}
\end{minipage}

The above is also possible without the capt-of package if you're using the caption package or a KOMA script class like scrartcl.

But the normal way of including figures is with the figure environment:

\begin{figure}
  \centering
  \includegraphics{example-image-duck}
  \caption{A friendly looking duck\label{fig:duck}}
\end{figure}

Usage of the center environment doesn't seem like a good idea, because it won't prevent page breaks between the graphic and its caption.

| 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.