Monday, May 16, 2011

Top 10 LaTeX Packages

May 16, 2011 4:10 pm

1. amsmath, amsfonts

Particularly handy for rendering matrices. amsmath has a set of tailored matrix environments. For example here are three examples that use pmatrix, bmatrix and Bmatrix. ams also provide a host of new symbols, such as $\therefore$, $\varnothing$, and $\thickapprox$ and new alignment environments. See the user document for further details.

$$\begin{pmatrix} 1 & 2 & 3 & 4\\ 5 & 6 & 7 & 8\\ 9 &10 &11 &12\\ 13&14 &15 &16 \end{pmatrix} \begin{bmatrix} 1 & 2 & 3 & 4\\ 5 & 6 & 7 & 8\\ 9 &10 &11 &12\\ 13&14 &15 &16 \end{bmatrix} \begin{Bmatrix} 1 & 2 & 3 & 4\\ 5 & 6 & 7 & 8\\ 9 &10 &11 &12\\ 13&14 &15 &16 \end{Bmatrix} $$

2. TikZ/Pgf

The TeX world has gone through many approaches that permit the inclusion of figures into LaTeX documents. The latest approach and one gaining popularity is TikZ/Pgf. The best way to appreciate this package is to visit the examples site where numerous user contributed examples can be found. TikZ has a steep learning curve but the results are outstanding.

3. pgfplots

Along side TikZ there is the companion package pgfplots which removes much of the effort in drawing data or function plots within LaTeX documents. See the example site for numerous examples of what pgfplots can do, including 3D plots.

4. geometry

Every struggled with getting page dimensions set for your latest work? If so, the geometry package is the answer. The geometry package can be used to control the overall margins, and text area of your document. For example, the following sets up pages for a standard 6 by 9 book format with additional space for the binding edge, taking into account that the pages will be double-sided.

\usepackage[paperwidth=6in,paperheight=9in,top=1in,left=0.66in,right=0.66in,textheight=6.8in,bindingoffset=5mm,twoside]{geometry}

5. xcolor

If you want driver-independent color and access to different kinds of color specifications, then xcolor is the package. xcolor comes with an enormous set of standard colors in addition to being able to mix your own in a wide variety of ways, including rgb, cmyk, hsb, to name but a few.

6. booktabs

The standard tables support in LaTeX isn't very good at spacing the rows. Instead I use booktabs which does a much better job.

\begin{center}
{\bfseries Normal LaTeX}\newline\newline
\begin{tabular}{llr}
\hline \multicolumn{2}{c}{Item} \\ \cline{1-2} Animal & Description & Price (\$) \\ \hline Gnat  & per gram & 13.65 \\ & each     &  0.01 \\ Gnu   & stuffed  & 92.50 \\ Emu   & stuffed  & 33.33 \\ Armadillo & frozen & 8.99 \\ \hline \end{tabular} \end{center} [+preamble] \usepackage{booktabs} [/preamble] \begin{center}  \newline\newline{\bfseries With Booktabs}\newline\newline   \begin{tabular}{llr} \toprule \multicolumn{2}{c}{Item} \\ \cmidrule(r){1-2} Animal & Description & Price (\$) \\ \midrule Gnat  & per gram & 13.65 \\ & each     &  0.01 \\ Gnu   & stuffed  & 92.50 \\ Emu   & stuffed  & 33.33 \\ Armadillo & frozen & 8.99 \\ \bottomrule
\end{tabular}
\end{center}

7. fancyhdr

fancyhdr is useful for customizing the headers and footers in your document. For example, to place today's date on the right hand side of the page header and the title of the document on the left side, one can use:

\lhead{My Thesis}
\rhead{\today}

fancyhdr also comes with an additional pagestyle called fancy, as in \pagestyle{fancy}. fancy will add a line at the top of every page (except pages such as new chapter, title page etc.).

8. quotchap

quotchap redesigns the chapter heading page. In particular it will put a large grey chapter number to the right of the page and can also be used to optionally add chapter quotations

9. hyperref

I tend to always use pdflatex these days to generate my output. In generating pdf files, it is very useful to have hyperlinks automatically inserted into the document. hyperref is the package to use.  These include hyperlinks from the chapter contents page, equation references, figure references and index references. Adding hyperlinks to your pdf output is very simple, just include the line:

\usepackage{hyperref}

near the start of your document. There are many options for changing the style, including color and how the hyperlink is presented.

10. kbordermatrix

Adding column and row labels to matrices is not always easy. kbordermatrix however does the trick. An example is shown below. There is a lot more flexibility to kbordermatrix than shown here so I refer you to the documentation for more details.

\kbordermatrix{\mbox{indices}&1&2&3&4\\
1&M_{1,1}&M_{1,2}&M_{1,3}&M_{1,4}\\
2&M_{2,1}&M_{2,2}&M_{2,3}&M_{2,4}
}

I am sure others will have their own favorites.

Packages I've used on Occasion

1. KOMA-Script and Memoir class

Koma-Script and Memoir class are both replacements for the traditional article/report/book classes in LaTeX with the memoir class being a replacement for report and book. Both come with extensive documentation an require some initial effort to use. A summary of the capabilities of Koma-script can be found at stackexchange.

Details on the memoir class can be found at the PracTeX Journal article. To use these packages effectively requires a thorough reading of the manuals.

2. natbib

natbib is a reimplementation of the \cite command. As a result it is much more flexible in the way references can be cited.  See reference sheet for details.

3. subfigure

subfigure is the package to use if you need to place small figure or tables within a single figure. It supports options to set the position and captioning. The following code will place three figures in a line. If there isn't enough space, the package will automatically place the overflow subfigures on to the next line.

\begin{figure}[htb]

\subfigure[Subfigure 1 caption]{
   \includegraphics{subfigure1.pdf}
   \label{fig:subfig1}
 }

 \subfigure[Subfigure 2 caption]{
   \includegraphics{subfigure2.pdf}
   \label{fig:subfig2}
 }

 \subfigure[Subfigure 3 caption]{
   \includegraphics{subfigure3.pdf}
   \label{fig:subfig3}
 }

\label{myfigure}
\caption{Global figure caption}
\end{figure}


No comments: