Created at:

Modified at:

My LaTeX notes

Since I am not a heavy user of the LaTeX typesetting system, I decided to write down tips for myself, because I use it only once in a while. I frequently forget important things about that and, although I have a set of bookmarks related to LaTeX, they are spread so I cannot find them when I want. To avoid using a search engine for every feature of LaTeX I need, here comes these notes.

LaTeX

Figures

Using the figure environment

In order to use figures, first by including the graphicx package::

    \includegraphics

Them by using the figure environment::

    \begin{figure}[h]
      \begin{center}
        \includegraphics[width=.5\paperwidth]{path_to_picture.png}
        \caption{Caption comes here}
        \label{fig:labelhere}
      \end{center}
    \end{figure}

It is interesting to point out the [width.5paperwidth] parameter, that sets the picture width to half of page width.

Figures in different chapters have the same number

In the default class of LaTeX, pictures are numbered 1.1, 1.2 for chapter 1; 2.1, 2.2 for chapter 2 and so on. ABNT uses just one number (the second one), so you may have figure 1 in chapter 1 and figure 1 in another chapter! This is confusing, but easily fixable, with the chngcntr package. Include it first::

    \usepackage{chngcntr}

Then, tell it to count figures outside of chapter division (I use to include this line just after begin{document}::

    \counterwithout{figure}{chapter}

Tex Frequently Asked Questions -- question label "running-nos"

General tips

Remove a number of a page

To remove a number from a page, just use the thispagestyle{empty} command.

Cross-references

Cross-references are one of the most powerful features of LaTeX in my opinion. See this figure example::

    Here some sh code at figure \ref{fig:sh-code}:

    \begin{figure}
      \caption{sh code}
      \label{fig:sh-code}
      \begin{verbatim}
        echo "bla";
      \end{verbatim}
    \end{figure}

Important commands here are:

LaTeX/Labels and Cross-referencing - Wikibooks, open books for an open world

LaTeX Tricks: Figures

"Small" verbatims

(2012-04-13)

begin{verbatim} .. end{verbatim} is used for text blocks. If you want to put a small verbatim text inside a paragraph, just use::

    \verb|my verbatim text|

See that, any character can be a verb delimiter, like pipe in the last example. Another example using plus::

    \verb+my verbatim text+

For more information, see this__.

__ http://en.wikibooks.org/wiki/LaTeX/Paragraph_Formatting#Verbatim_Text

The listings package --------------------

(2012-04-16)

I recently discovered that there is the listings package that would allow you to list program's source code and color them according to their syntax. To use the package, just::

    \usepackage{listings}

Use the lstset{} command to configure listing options and just use it that way::

    \lstinputlisting[
                      language=VHDL,
                      caption={Description of a VHDL code},
                      label={lst:my_vhdl_code}
                    ]{path_to_file.vhd}
    \vspace*{0.4cm}

LaTeX/Source Code Listings - Wikibooks, open books for an open world

"Fields" (underscores) to be written on after printing

(2012-04-16)

You may want create some underscored fields so allowing readers of the document write on it like a date field (____/__/__). A single underscore in LaTeX is ugly, so we create a new command, called xline{}::

    \newcommand{\xline}[0]{\noindent\underline{\makebox[0.5cm][l]{}}}

The xline{} draws a stylish line 0.5 cm width. Try it by yourself.