2007
07.19

LaTeX tips & tricks

During my internship I quickly got frustrated with OpenOffice.org Writer. Halfway through I switched to LaTeX and never looked back. LaTeX is far from perfect, but it’s a hell of a lot better than any random wordprocessor. There is a very good introductory text available on LaTeX, it’s called lshort. Here are some good articles on why you should use LaTeX.

During the past few month, I’ve learned quite a few LaTeX tricks, which I’ll share with you:

VarioRef

Normal references will insert a reference to a page number, even if the object being referenced is on the same page. VarioRef will change this behavior into something more intelligent. When I reference an object on the following page, VarioRef will produce something like “overleaf” instead of “on page 14″. Here is how you can use VarioRef (in Dutch):

\usepackage[english,dutch]{babel}

\usepackage[dutch]{varioref}

\label{sec:statistical}

\vref{sec:statistical}

Rotating

Every once in a while your tables get to wide to fit on a portrait A4 page. Don’t panic, the rotating package will come to the rescue. Using the sideways environment (defined by the rotating package) you can rotate an object (a table for example) 270/90 degrees. Please note that only the object is rotated. This means page headers and footers remain as they were, not disrupting the document flow.

\usepackage{rotating}

\begin{sideways}

\end{sideways}

Elegant section numbering

For my thesis I wanted the section numbering to be visible in the margins. This way the section titles would be nicely lined up with my text, producing a very elegant look. Here is how you can do it:

\usepackage{sectsty}
\makeatletter\def\@seccntformat#1{\protect\makebox[0pt][r]{\csname the#1\endcsname\hspace{12pt}}}\makeatother

Semibold instead of Bold

If you have a Semibold variant of your font available I highly recommend you abstain from using Bold. LaTeX can do this for you (automatically), the following command will replace all bold fonts with semibold ones.

\renewcommand{\bfdefault}{sb}

Lowering glyphs below their baseline

In my thesis I used old style figures. When using the paragraph symbol followed by such old style figures, the paragraph symbol looked as if it was placed to high. You can define your own custom commands, with which you can lower of raise any glyph respectively to their baseline like this:

\newcommand\Ss{\raisebox{-1.25pt}{\S}}

Phantom objects

When creating my halftitle page, I had issues lining up everything. I always had a discrepancy somewhere. The phantom command saved my day. Any phantom object will occupy exactly the same space as if it were normally there, except it won’t. A space will be filled with exactly the same dimensions as the object would normally occupy:

\phantom{Whazaaap}

Background picture

For some creative typesetting you might want to include a picture into the background of your document. Create your own JPEG at 150dpi for ebook uses and 300dpi for printing, then include it into the document like this:

\usepackage{eso-pic}
\AddToShipoutPicture{\includegraphics[width=\paperwidth,height=\paperheight]{background.jpg}}

Custom font size commands

The default LaTeX font size commands are rather limited. They do not allowed you to insert really large text. This is done for a reason, generally you wouldn’t need to. However if you feel you really need to have some larger text, you can define your own size command. The following example defines 50pt text with a 55pt line height:

\newcommand{\gargantuan}{\fontsize{50}{55}\selectfont}

Modifying enumeration styles

For example if you would want to typeset one of the Creative Commons license texts, you would need to change the second level enumeration style to alphabetical enumeration. You can do it like this:

\renewcommand{\labelenumii}{\alph{enumii}.}

Custom PDF Metadata

If your not happy with the PDF metadata generated by pdfLaTeX, you can override it like so:

\usepackage[pdftex]{graphicx,hyperref}

\pdfinfo{
/Title (LaTeX Tricks)
/Subject (LaTeX)
/Author (Pascal))
/Keywords (latex tricks)
/Creator (LaTeX 2e)
/Producer (pdfTeX for Linux)}

SmallCap Abbreviations
If you regularly need to smallcap a common abbreviation, it quickly gets rather old having to change “DEC” into “\textsc{dec}” every single time. But there is another way. Define an abbrev command, and then define a specific command for every common abbreviation:

\usepackage{textcase}

\usepackage{xspace}
\newcommand\abbrev[1]{\textsc{\lowercase{#1}}\xspace}
\newcommand\DEC{\abbrev{DEC}}

Leading / Linespread

Having a little extra space between lines makes text more legible. I generally prefer a line spread of 1.1:

\linespread{1.1}

Manual Kerning

Sometimes the kerning tables of font will not suffice. With the kern command you can move two glyph closer together, or further apart:

\kern+1pt

Changing The Margins

Generally LaTeX uses proper margins. Good documents have large margins. Anything below 3cm on A4 paper should be considered a sin. However, your margins can be a good tool to do some copyfitting. Copyfitting is the process where you make your paragraphs fit on a page, so that all the text is nicely aligned, and paragraphs are minimally spread across several pages. You can slightly change the margins of your document using the geometry package to accommodate this process. The geometry package will automatically recalculate the other margins based on the inner margin you specify:

\usepackage[inner=3.83cm]{geometry}

No Comment.

Add Your Comment

Comments are closed.