Friday, 24 November 2017

Step 3 : References and Figures

Step 3: References and Figures

Now the situation may come about when writing a document where we need to refer to a section/figure etc, so we need to know how to do that. It is done by using labels, and then refering to them.

So in my text I need to refer to my awesome chapter, I'll add a label underneath the chapter line like so;

\chapter{Awesome Chapter}
\label{chp:awe_chp}

It doesn't really matter what you call your labels, but I find it helps to stick to the basic principle of saying what the label refers to, then adding a label name, for example;

chp: is for a chapter
sec: for a section
ssec: for a subsection
fig: for a figure
tab: for a table
eq: for an equation

Refering to a label

Now that we have defined our labels, lets refer to them, so in the text we write \ref{label name}, for example

The derivation and explanation of this super important equation can be seen in chapter \ref{chp:awe_chp}.

This will print the following;

The derivation and explanation of this super important equation can be seen in chapter 2.

Where the reference to a label is replaced by the chapter/section/whatever number.

Figures

Now adding pretty pictures and graphs to your document follows the same procedure, first we add the picture to your document folder.

Now call the picture something easy to remember, such as 'picture'

Back to latex, we add the following code;

\begin{figure}[!th]
\centering
\includegraphics[scale=1]{picture.png}
\caption{An awesome caption to go with my picture}
\label{fig:picture}
\end{figure}

So the \begin{figure} is self-explanatory, however the options in square brackets [!th] are not. These tell latex that I want to put my figure here, no really here. This is how I like to do my figures in latex, but other people like to leave latex to decide the best place to put a figure.

Next the \centering command, this centers the figure in the middle of the page width, include graphics is where we say which file to input, and the \caption command adds a line of text under the picture.

to refer to this in the text we simply type;

As can be seen in figure \ref{fig:picutre}.

Which will be output as;

As can be seen in figure 2.1.



So there ends the quick introduction to latex and how to make a document.

No comments:

Post a Comment