About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Latest news 2019-11-04: The giveaway of two signed copies of “Quack, quack, quack. Give my hat back!” has closed and the winning entrants have been selected. Thank you to everyone who took part.


4.5.1 Changing the Font Style

There are two basic ways of changing fonts: you can either change the font for a small selection of text, for example, if you want to emphasize a word, or you may wish to change the font “from this point onwards”. The commands shown in Table 4.5 are of the first type (text-block commands), whereas those shown in Table 4.6 are of the second type—a declaration (or modal command).

Note:

Don't be tempted to use \bf, \md, \it, \sl, \sc, \sf, \tt or \rm. These commands are obsolete [15].[What's wrong with \bf, \it etc.?]

If you use an italic or slanted font declaration, such as \itshape, you will need to add an italic correction \/ at the end of the block of text, when the last letter of the sloping text leans too far over. This isn't necessary for text-block commands, such as \textit, just for the modal commands. The effect is more noticeable when part of a word is stressed, particularly with certain fonts.

Example:

In the code below, the first instance of “repeated” doesn't have an italic correction but the second does:

{\itshape repeated}ly {\itshape repeated\/}ly

Using Computer Modern:

repeatedly repeatedly

Using Helvetica:

repeatedly repeatedly

Using Antykwa Toruńska typeface:

repeatedly repeatedly


Table 4.5: Font Changing Text-Block Commands
 Command Example Input Corresponding output  
     (Computer Modern)  
 \textrm{<text>} \textrm{roman} text Roman text  
 \textsf{<text>} \textsf{sans serif} text sans serif text  
 \texttt{<text>} \texttt{typewriter} text typewriter text  
 \textmd{<text>} \textmd{medium} text medium text  
 \textbf{<text>} \textbf{bold} text bold text  
 \textup{<text>} \textup{upright} text upright text  
 \textit{<text>} \textit{italic} text italic text  
 \textsl{<text>} \textsl{slanted} text slanted text  
 \textsc{<text>} \textsc{Small Caps} text Small Caps text  
 \emph{<text>} \emph{emphasized} text emphasized text  
 \textnormal{<text>} \textnormal{default} text default text  
        

Note that if you want to typeset an URL, rather than using \texttt it is better to use

\url{<address>}

which is defined in the url package. For example:

\url{http://theoval.cmp.uea.ac.uk/~nlct/}

produces:

http://theoval.cmp.uea.ac.uk/ nlct/

(Note there is no need to do anything with the ~ (tilde) special character if you use it in the argument of \url.)


Table 4.6: Font Changing Declarations
 Declaration Example Input Corresponding output  
     (Computer Modern)  
 \rmfamily \rmfamily roman text Roman text  
 \sffamily \sffamily sans serif text sans serif text  
 \ttfamily \ttfamily typewriter text typewriter text  
 \mdseries \mdseries medium text medium text  
 \bfseries \bfseries bold text bold text  
 \upshape \upshape upright text upright text  
 \itshape \itshape italic text italic text  
 \slshape \slshape slanted text slanted text  
 \scshape \scshape Small Caps text Small Caps text  
 \em \em emphasized text emphasized text  
 \normalfont \normalfont default text default text  
        


Environments can be used instead. Each environment has the same name as its corresponding declaration, but without the preceding backslash. For example:

\begin{sffamily}Some sans-serif text.\end{sffamily}

yields:

Some sans-serif text.

You can combine a font family with a given shape and weight using a variety of methods.

Examples:

  1. Localised declarations:

    {\sffamily\slshape Some slanted sans-serif text.}

  2. Declarations that later get explicitly reset:

    \sffamily\slshape Some slanted sans-serif text.\normalfont

  3. Mixing text-block and modal commands:

    \textsf{\slshape Some slanted sans-serif text.}

  4. Nested commands:

    \textsf{\textsl{Some slanted sans-serif text.}}

  5. Mixing environments and declarations:

    \begin{sffamily}\slshape Some slanted sans-serif text.\end{sffamily}

All of the above produce the same output:

Some slanted sans-serif text.

[Warning: “Font shape ... not available”]Note that some combinations are not available, in which case LaTeX will give a warning message, and will substitute the font for what it considers to be the closest available match.

Example:

\textsc{\bfseries Text}

With the Antykwa Toruńska typeface, this appears as:

Text (in bold small caps)

whereas with Computer Modern, the result is:

Text (in bold)

This is because Computer Modern doesn't have a bold small-caps font, so it just uses bold. LaTeX gives the following warning:
LaTeX Font Warning: Font shape `T1/cmr/b/sc' undefined
(Font)              using `T1/cmr/b/n' instead on input line 2792.
Most sans-serif fonts don't provide a small-caps variant, so

\textsf{\scshape Text}

will either appear in regular sans-serif or small-caps serif, depending on the font in use. Using Libris sans-serif the result is:

Text (in sans-serif)

whereas using Computer Modern Sans, the result is:

Text (in small caps)


4.5.1.1 Emphasizing Words or Phrases

The command \emph, the declaration \em and the environment em behave slightly differently to the corresponding \textit command, \itshape declaration and itshape environment. The latter group simply use an italic font, whereas the former will toggle between sloping and upright. So if the surrounding font is upright then \emph, \em and em will use the sloping font, but if the surrounding font is italic or slanted, \emph, \em and em will use an upright font. This is particularly useful in abstracts where the abstract font varies between class files. It is recommended that if your intention is to emphasize something, you should use \emph etc. rather than \textit etc.

Examples:

  1. Emphasized text in upright surrounding:

    Some \emph{emphasized} text.

    yields

    Some emphasized text.

  2. Emphasized text in italic surrounding:

    {\itshape Some \emph{emphasized} text.}

    yields

    Some emphasized text

  3. Emphasized text in upright sans-serif surrounding:

    {\sffamily Some \emph{emphasized} text.}

    yields

    Some emphasized text


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs