LaTeX: Difference between revisions

From Elvanör's Technical Wiki
Jump to navigation Jump to search
No edit summary
Line 65: Line 65:


* You can generate a tabular environment with \begin{tabular}. You give the definitions of the columns in the mandatory argument. Note that borders are created only if you enter "|" characters in the column definition area.
* You can generate a tabular environment with \begin{tabular}. You give the definitions of the columns in the mandatory argument. Note that borders are created only if you enter "|" characters in the column definition area.
* The tabular is usually included in a floating table environment. So the code would be like:
<pre>
\begin{table}[h!]
\begin{tabular}{|p{4cm}|c|l|}
...
\end{tabular}
\end{table}
</pre>
* You cannot use a footnote inside a table. The best alternative is to use the ''threeparttable'' package, with the \tnote command and '''tablenotes''' environment.


* The \parbox command allows you to create a paragraph box (eg, it will be in paragraph mode, which means its content can span several lines). This command takes a mandatory width argument, and an optional one controlling the vertical alignment of the contents.
* The \parbox command allows you to create a paragraph box (eg, it will be in paragraph mode, which means its content can span several lines). This command takes a mandatory width argument, and an optional one controlling the vertical alignment of the contents.

Revision as of 17:58, 28 October 2008

LaTeX is a fantastic typesetting package. Unfortunately it has a big problem: not a lot useful documentation. So this is a collection of useful tips I have learnt while spending a lot of time googling for LaTeX documentation.

Documentation

  • I found the following tutorials, books or cheatsheets useful:
    • The Not So Short Introduction to LaTeX 2e (general introduction).
    • TeX for the impatient (more complete book).
    • Latex cheat sheet (very useful list of commands).
  • They are free and available online.

Good resource site.

Basic Concepts

  • In LaTeX there are environments (started with the \begin command) and commands. These are separate concepts although sometimes they seem to overlap. For example you create a tabular environment but you give a command to generate a paragraph box (\parbox).
  • Sometimes you have to protect commands with the \protect command (which will apply to the next command). This happens when you have commands inside a caption for example. Note that the \\ (for a line break) also have to be protected.

Packages

  • The url package allows you to output URLs in a better looking way. Just use the \url{} command.
  • The changepage package (previously chngpage) allows you to change the width of the page momentarily, thus reducing (or increasing) margins.
  • The graphicx package seems necessary to deal with images, import it like this:
\usepackage[pdftex]{graphicx}

Techniques

Choosing a document class

  • The letter class is not recommended, because it does not allow you to use sections, subsections, etc. The article class can be used as a general purpose class, it's not mandatory to have a title, abstract or bibliography.

Spacing and Page breaks

  • Use \pagebreak to make a page break.

Symbols

  • To use the Euro symbol, use \usepackage[official]{eurosym}. You can then write the symbol with the command \euro, or use \EUR{50} to directly write a monetary amount.

Font size and style

  • Use the commands \tiny, \large, \Large, \huge to change the font size.
  • Use {\bf } for boldface, {\it } for italics.

Alignment

  • By default LaTeX justifies a paragraph. Should you need to have it aligned use:
\begin{flushright}
This is some text.
\end{flushright}
  • There is also a \begin{flushleft} environment, of course. To center a block, use the \begin{center} command.
  • You can align a section title like this:
\section*{\begin{center}STATUTS\end{center}}
  • \begin{flushright} starts a new paragraph. Sometimes you don't want that happening, in which case you can use the \raggingleft command which does the same thing (warning: the left/right arguments are inversed from flush).

Tables and Boxes

  • You can generate a tabular environment with \begin{tabular}. You give the definitions of the columns in the mandatory argument. Note that borders are created only if you enter "|" characters in the column definition area.
  • The tabular is usually included in a floating table environment. So the code would be like:
\begin{table}[h!]
\begin{tabular}{|p{4cm}|c|l|}
 ...
\end{tabular}
\end{table}
  • You cannot use a footnote inside a table. The best alternative is to use the threeparttable package, with the \tnote command and tablenotes environment.
  • The \parbox command allows you to create a paragraph box (eg, it will be in paragraph mode, which means its content can span several lines). This command takes a mandatory width argument, and an optional one controlling the vertical alignment of the contents.

Tools

Viewer

  • My favorite viewer when writing LaTeX files is kpdf. It automatically reloads changes to the underlying document which is very nice.

LaTeX Distribution

  • As of 2008, the best available distribution for Linux/UNIX seems to be TexLive (version 2007, 2008 is not released yet). It has a stable ebuild for Gentoo Linux (the old tetex distribution is now obsolete).

Eclipse Support (via Texlipse)

  • The support is good overall. It allows you to mix freely *.tex files within another project (with PHP files for example). It will configure a LaTeX builder for the project, which will build your document. However, it is intended that only one document is created (although you can combine multiple source TeX files to create it).
  • Check the project properties to define which is the main LaTeX source file and which document will be built. You can also define what program will be used for the build (pdflatex etc).

Code Examples

  • Two columns layout:
\begin{tabular}[t]{lr}
\parbox[t]{5cm}{11 bis, rue de Genève\\
91140 Villebon-sur-Yvette\\
France\\

(33) 09.52.29.23.58 \\
(33) 06.28.33.13.68}
& \parbox[t]{7cm}
{
	\raggedleft
    \url{jean-noel.rivasseau@polytechnique.org}\\
    \url{http://www.elvanor.net/}\\
	\url{http://www.shoopz.com/}
}
\end{tabular}
  • Inclusion of an image, while reducing the page's margins for this image (you need to import changepage package):

\begin{figure}[t] \begin{adjustwidth}{-4cm}{-4cm} \begin{center} \includegraphics[width=18cm]{kameleon-1} \end{center} \end{adjustwidth} \caption{Write your caption here.} \end{figure}