Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 38 ยท Documents and Text Formatting

Text Formatting: Bold, Italic and Emphasis

Format text in LaTeX with \textbf, \textit, \emph, \texttt, \textsc and \underline, learn semantic emphasis, nesting rules, alignment, quotes and verbatim code.

Plain paragraphs get you far, but sooner or later you need bold words, italic titles, code in a typewriter font or a centered line. LaTeX offers a small, consistent set of commands for this. The best habit is to ask what the text means, because LaTeX can then style it appropriately and consistently across the whole document.

Bold, italic and friends

Each style has a command that takes the text as an argument.

Command Result Typical use
\textbf{text} bold Defined terms, strong emphasis
\textit{text} italic Titles of books, foreign words
\textsl{text} slanted Rarely needed; a slanted roman
\textsc{text} SMALL CAPS Names, acronyms in headings
\texttt{text} typewriter Code, file names, commands
\textsf{text} sans serif A contrasting face
\textrm{text} roman Return to the default family
\underline{text} underlined Use rarely; hyphenation does not work inside it
LATEX
Use \textbf{bold} for key terms, \textit{italic} for titles, and
\texttt{main.tex} for file names. Names look good in \textsc{Small Caps}.

\emph: emphasis with meaning

\emph{text} means "this is emphasised". In normal text it prints italic. The clever part is that inside already-italic text it switches back to upright, so emphasis never disappears.

LATEX
This is \emph{really} important.
\textit{This sentence is italic, and \emph{this word} stands out.}

Prefer \emph over \textit for stress, and \textit for things that are italic by convention (a book title). If a publisher later wants emphasis in bold, you change the definition of \emph once instead of editing hundreds of places.

Combining styles and nesting

Commands can be nested. Inner commands inherit what the outer ones set.

LATEX
\textbf{bold and \textit{bold italic}}
\texttt{\textbf{bold code}}

Watch the braces. The argument ends at the matching closing brace, so a missing } makes the styling run on, and usually causes an error at the end of the file such as "Runaway argument" or "File ended while scanning".

Below is a stand-in that understands \textbf, \textit, \emph, \texttt, \textsc and \underline. It is not LaTeX, so it cannot flip italic back to upright, but it shows how arguments in braces become styled text. Change the text and see how the output follows.

Styling commands (stand-in, not a real compiler)

Switches: styling a whole stretch of text

The \textXX{...} commands style their argument. Another family, the declarations, switch a style on until the end of the current group.

LATEX
{\bfseries Everything in this group is bold, even
across several sentences.} Back to normal here.

\begin{center}
  \itshape A centered italic line.
\end{center}
Declaration Style
\bfseries bold
\itshape italic
\scshape small caps
\ttfamily typewriter
\sffamily sans serif
\normalfont reset to the default

Use the \textXX{} form for short stretches and the declarations for longer blocks or inside definitions.

Alignment

Text is justified by default. Three environments change this.

LATEX
\begin{center}   Centered text   \end{center}
\begin{flushleft}   Left aligned, ragged right   \end{flushleft}
\begin{flushright}   Right aligned   \end{flushright}

Inside a group or a command, the declarations \centering, \raggedright and \raggedleft do the same thing without extra vertical space. Ragged-right text often looks better in narrow columns, where justification creates large gaps between words.

Quotation marks

Use two backticks and two apostrophes for double quotes, one of each for single quotes.

LATEX
``Hello,'' she said. `Yes,' he replied.

The csquotes package gives a smarter \enquote{text} command that adapts to the language and nests properly, and is the best choice for longer documents.

For a longer quotation set apart from the text, use the quote environment (short quotations) or quotation (several paragraphs).

LATEX
\begin{quote}
  Programs must be written for people to read, and only incidentally
  for machines to execute.
\end{quote}

Verbatim and inline code

Reserved characters such as \, { and % are a nuisance when you want to show code. The verbatim environment and the \verb command print text exactly as typed, with no interpretation.

LATEX
Run \verb|pdflatex main.tex| to compile.

\begin{verbatim}
\documentclass{article}
\begin{document}
Hello \textbf{world}
\end{document}
\end{verbatim}

\verb|...| uses any character you choose as a delimiter (here |), as long as it does not occur inside. Two limits: \verb cannot appear inside the argument of another command (for example within \textbf{...} or a footnote), and verbatim does not wrap long lines. For serious code listings you will use the listings or minted packages, covered in the packages chapter.

Emphasis, dashes and ligatures: the small things

  • Leave one space after a sentence-ending period; LaTeX adds a little extra after full stops. After an abbreviation like "Dr." or "e.g.", write Dr.\ Smith or e.g.\ this (backslash-space) so LaTeX does not treat the period as a sentence end.
  • Use ~ for a non-breaking space: Figure~3, Dr.~Smith, 5~km. The two words never separate across lines.
  • Use -- for ranges (pp.~10--12) and --- for a break in thought.
  • To print three dots correctly use \ldots, not three periods.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which command is the best choice to stress a word in running text?

    \emph marks meaning and flips back to upright inside italic text. Underlining is rarely good practice.
  2. 2. What is the difference between \textbf{...} and \bfseries?

    The text commands take an argument; declarations such as \bfseries stay active until the group ends.
  3. 3. How do you type an opening double quote correctly?

    Two backticks open, two apostrophes close. A plain " prints a closing quote.
  4. 4. Why use Figure~3 instead of Figure 3?

    ~ glues the words together on one line.

Summary

  • \textbf, \textit, \texttt, \textsc and \underline style short pieces of text.
  • \emph expresses emphasis and toggles correctly inside italics.
  • Declarations like \bfseries and \itshape switch a style on for a group.
  • center, flushleft and flushright align text; use `` and '' for quotes.
  • \verb and verbatim show code exactly; ~ is a non-breaking space.

Next: Fonts, Sizes and Spacing