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 typea declaration (or modal command).
Note:
\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:
Using Computer Modern:
Command | Example Input | Corresponding output | ||
---|---|---|---|---|
(Computer Modern) | ||||
\textrm {<text>} |
\textrm{roman} text |
|||
\textsf {<text>} |
\textsf{sans serif} text |
|||
\texttt {<text>} |
\texttt{typewriter} text |
|||
\textmd {<text>} |
\textmd{medium} text |
|||
\textbf {<text>} |
\textbf{bold} text |
|||
\textup {<text>} |
\textup{upright} text |
|||
\textit {<text>} |
\textit{italic} text |
|||
\textsl {<text>} |
\textsl{slanted} text |
|||
\textsc {<text>} |
\textsc{Small Caps} text |
|||
\emph {<text>} |
\emph{emphasized} text |
|||
\textnormal {<text>} |
\textnormal{default} text |
|||
Note that if you want to typeset an URL, rather than using
\texttt
it is better to use
which is defined in the url package. For example:
produces:
\url
.)
Declaration | Example Input | Corresponding output | ||
---|---|---|---|---|
(Computer Modern) | ||||
\rmfamily |
\rmfamily roman text |
|||
\sffamily |
\sffamily sans serif text |
|||
\ttfamily |
\ttfamily typewriter text |
|||
\mdseries |
\mdseries medium text |
|||
\bfseries |
\bfseries bold text |
|||
\upshape |
\upshape upright text |
|||
\itshape |
\itshape italic text |
|||
\slshape |
\slshape slanted text |
|||
\scshape |
\scshape Small Caps text |
|||
\em |
\em emphasized text |
|||
\normalfont |
\normalfont default text |
|||
Environments can be used instead. Each environment has the same name as its corresponding declaration, but without the preceding backslash. For example:
yields:
You can combine a font family with a given shape and weight using a variety of methods.
Examples:
- Localised declarations:
- Declarations that later get explicitly reset:
- Mixing text-block and modal commands:
- Nested commands:
- Mixing environments and declarations:
All of the above produce the same output:
[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:
With the Antykwa Toruńska typeface, this appears as:
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
will either appear in regular sans-serif or small-caps serif, depending on the font in use. Using Libris sans-serif the result is:
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:
- Emphasized text in upright surrounding:
yields
- Emphasized text in italic surrounding:
yields
- Emphasized text in upright sans-serif surrounding:
yields
This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).