next up previous contents index
Next: 4.4.2 Changing the Font Up: 4.4 Simple font changing Previous: 4.4 Simple font changing   Contents   Index


4.4.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.4 are of the first type (text-block commands), whereas those shown in table 4.5 are of the second type--a declaration (or modal command). [What's wrong with \bf, \it etc.?]

If you use an italic or slanted font declaration, 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. For example, compare

{\itshape Some italic text} back to upright.

which yields

Some italic text back to upright.

to

{\itshape Some italic text\/} back to upright.

which yields

Some italic text back to upright.

In the first example, the final letter "t" in the word "text" leans too far over the space. In the second example, extra space (known as italic correction) is inserted.

If you use one of the text-block commands, such as \textit, the italic correction is dealt with by the command, so the above example would equivalent to:

\textit{Some italic text} back to upright.

which again yields

Some italic text back to upright.

The effect is more noticeable when part of a word is stressed. For example:

{\itshape repeated}ly \textit{repeated}ly

produces

repeatedly repeatedly




Table 4.4: Font changing commands
Command Example Input Corresponding output
\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





Table 4.5: Font changing declarations
Declaration Example Input Corresponding output
\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, such as:

  1. Declarations:

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

  2. Mixing commands and declarations:

    \textsl{\sffamily Some slanted sans-serif text}
    

  3. Nested commands

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

  4. 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

Note that some combinations are not available, in which case LaTeX will give a warning message, [Warning: "Font shape ... not available"] and will substitute the font for what it considers to be the closest available match. [How to do bold-tt or bold-sc]

Note also that 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 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. The word emphasized is in italic the rest is upright.

  2. Emphasized text in italic surrounding:

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

    yields

    Some emphasized text. The word emphasized is upright the rest is in italic.

  3. Emphasized text in upright sans-serif surrounding:

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

    yields

    Some emphasized text. The word emphasized is in a slanted sans-serif font the rest is upright.


next up previous contents index
Next: 4.4.2 Changing the Font Up: 4.4 Simple font changing Previous: 4.4 Simple font changing   Contents   Index

Nicola L. C. Talbot. School of Computing Sciences. University of East Anglia. Last Modified: 2008-01-15 W3C HTML 3.2 Valid