References
Overview
Teaching: 10 min
Exercises: 5 minQuestions
How do I manage cross referencing inside a document ?
How do I make a table of contents?
Objectives
Refer to my figures, tables, equations or even chapters from within my document
Create a table of contents
References in LaTeX are internal links within your document. They allow you to refer to another part of the document easily. For instance, you might want to write “as I explained in the figure : xxx” and replace the xxx by the correct value.
In order to do that, you need to insert a tag to the element you want to refer to. It can be anything like a float, an equation, a chapter, etc. The command to specify a tag is \label{}
and the parameter is the name of the tag. The parameter can be anything you like (it’s usually a good practice to have a naming convention).
The command to get the position of the label is \ref{}
and the parameter is the name of the tag defined in the label described before. You can put the command anywhere in the document. The command \pageref{}
will display the number of the page in which is the label.
Table of contents
To define the hierarchical structure of the document LaTeX provides special commands that defines chapter, section, etc. :
\part{}
\chapter{}
\section{}
\subsection{}
\subsubsection{}
\paragraph{}
You can generate the table of contents of your document automatically during the compilation by using the
\tableofcontents
command.Other tables can be generated like
\listoffigures
or\listoftables
they will generate the list of figures or tables (float).
05-reference
Tex file : 05-reference.tex
%<-----> ADDED to minimal <----->
\tableofcontents
\newpage
Some introductory sentences, followed by the context of the work and information about the structure of the document. [...]
We will analyze the result using the Carpentry method in section \ref{sec:analysis}, then will present the results in section \ref{sec:results}.
\section{Analysis}\label{sec:analysis}
All the the analysis has been done using Python and LaTeX and are summarized in figure \ref{fig:analysis}
\begin{figure}[h]
\includegraphics[width=5cm]{fig/phd050611s}
\caption{A beautiful figure that explain everything (from : http://phdcomics.com/comics/archive.php?comicid=1431)}
\label{fig:analysis}
\end{figure}
\section{Results}\label{sec:results}
Bla bla bla [...]
\section{Conclusion}\label{sec:conclusion}
As described in section \ref{sec:analysis} and \ref{sec:results} respectively on page \pageref{sec:analysis} and \pageref{sec:results}, we can conclude that reference in LaTeX is a great feature.
Compilation : 05-reference.pdf
Exercises
Float label
I would like to label my float and call this label
fig:myfig
.In order to do that I can write :
\begin{figure} \label{fig:myfig} \includegraphics[width=5cm]{fig/phd051608s} \caption{Where you sit in class/seminar. And what it says about you (from : http://phdcomics.com/comics/archive.php?comicid=1017)} \end{figure}
\begin{figure} \includegraphics[width=5cm]{fig/phd051608s} \caption{Where you sit in class/seminar. And what it says about you (from : http://phdcomics.com/comics/archive.php?comicid=1017)} \end{figure} \label{fig:myfig}
\begin{figure} \tag{fig:myfig} \includegraphics[width=5cm]{fig/phd051608s} \caption{Where you sit in class/seminar. And what it says about you (from : http://phdcomics.com/comics/archive.php?comicid=1017)} \end{figure}
\begin{figure} \includegraphics[width=5cm]{fig/phd051608s} \caption{Where you sit in class/seminar. And what it says about you (from : http://phdcomics.com/comics/archive.php?comicid=1017)} \label{fig:myfig} \end{figure}
Solution
- and 4. are correct : The floats will be labeled correctly
- The label is not referencing the figure
- The command is
\label
not\tag
Add list of figures
At the end of my document, I would like to add a list of figures. Which command do I use ?
\listfigures{}
\begin{list}
\listoffigures
Solution
- Does not exist.
- Is the environment to create lists but does not automate the action.
- Is correct. Works the same way as
\tableofcontents
.
Subsections, sections and chapters
Your are writing a report. In your first chapter “State of the art”, you would like to include a section called “Methodology”. In this section, there are two subsections, “Information sources” and “Selection criterias”. How can you include this structure ?
Solution
\chapter{State of the Art} \section{Methodology} \subsection{Information sources} \subsection{Selection criteria}
Note : For
\chapter{}
to work, your document must be a book or a report.
Key Points
\part{}
,\chapter{}
,\section{}
,\subsection{}
,\subsubsection{}
,\paragraph{}
are used to specify the hierarchical structure of the documentthe
\label{key}
command add a tagthe
\ref{key}
command will place the correct number of the labelkey
during compilationthe
\pageref{key}
command will put the page of the labelkey
during compilationthe
\tableofcontents
command will be replace by the table of contents of the document