Adding and defining fonts

You can define the base font for your document and provide font support for monospaced fonts and font size specifications. Normally, you add font packages to your project stylesheet. This allows them to be used in any document that uses the stylesheet.

Setting fonts in LaTeX is not an obvious task. It is, to be honest, rather cumbersome. So, let’s start with the basics.

Fonts are packages which you add using the \usepackage command. For example, \usepackage{helvet}.


Note: A good document about using fonts in LaTeX, see Font selection in LaTeX: The most frequently asked questions - PDF file.


Setting base fonts for the entire document

For a project I used several fonts. I used Helvetica for the base font and Latin Modern as an alternate base font. Latin Modern is a set of true handmade vector fonts. In the stylesheet, I added the following commands.

1
2
3
\usepackage{helvet}                        % Base font for document
\usepackage{lmodern}                       % Alternate base font
\renewcommand{\familydefault}{\sfdefault}  % Changes the default family to Sans Serif

The first two set the base fonts for the document. The third command changes the default family to sans serif.

Using font declarations

You can add font declarations that are valid within the current scope in the document.


Note: Declarations mean they remain in effect until the end of the current group or environment. They are not like setting fonts in stylesheets, but are used throughout the document. Font families, series and shapes can be combined, for example \bfseries\itshape results in bold italic type.


You first add font declarations to allow you to select between pre-defined font families. Then within each font family you add declarations to select the type of font, such as weight, form, and so on.

1
2
3
\rmfamily  % Selects a roman family
\sffamily  % Selects a san serif family
\ttfamily  % Selects a monospaced font

You then add the following declarations within each font family by using the following:

1
2
\mdseries   % formats the font as regular, well, actually it keeps the font as is.
\bfseries   % makes the font Bold.

Text strings can be formatted using the following:

1
2
3
4
\upshate  % reverts the text back to normal
\slshape  % forward slants the text
\itshape  % italicizes the font
\scshape  % makes the text All Caps and Small Caps

Adding the microtype package

To improve readability, you can add the microtype package. If it is used, options and settings need to be made. The PostScript font Adobe Courier is used for monospace text.

1
2
\usepackage{microtype}
\usepackage{courier}

Allowing relative font sizes

To allow relative font size specifications, (e.g. \smaller, \larger) the package relsize is used.

1
\usepackage{relsize}

Setting fonts for table of contents

To control the fonts and formatting used in the table of contents, use the titles package and set the argument tocloft.

1
\usepackage[titles]{tocloft}

Redefine line spacing

You can redefine the spacing to make the text more aesthetically appealing.

1
2
\setlength{\cftbeforechapskip}{2ex}
\setlength{\cftbeforesecskip}{0.5ex}

Creating a courier text styles

You can create a courier text style and a default paragraph text style that can be applied as needed.

1
2
3
4
5
\newcommand\textstyleCourier[1]{\texttt{#1}}
\newcommand\textstyleDefaultParagraphFont[1]{#1}
\makeatletter
\newcommand\arraybslash{\let\@arraycr}
\makeatother

Making dummy text available

You can make dummy text available to use in the document with the lipsum package.

1
\usepackage{lipsum}