14

I want to have a subsection with the following name:

The synchronized Keyword

i.e., make the word "synchronized" appear in a code-like font. I tried doing this:

\subsection{The \ttfamily{synchronized} keyword}

but it also makes the word "keyword" in the code-like font. How can I only apply the font to one word?

lockstep
  • 250,273
Amir Rachum
  • 4,333
  • 6
  • 30
  • 37

2 Answers2

21

The LaTeX command is \texttt for a teletype font:

\subsection{The \texttt{synchronised} keyword}
Andrew Ho-Lee
  • 378
  • 3
  • 6
  • What I want to know is why the \ttfamily command exists at all if it pulls crap like that and the \texttt command works just fine. – Andrew Feb 16 '11 at 14:20
  • 2
    LaTeX 2.09 had only the modal commands (\tt etc), which in LaTeX2e were deprecated in favour of the longer form (\ttfamily) as they now select font axes rather than a single font. The command forms (\texttt) are similar, although they also, as noted by Villemoes, produce italic spacing correction.

    The command forms tend to be more useful when you just want to change a single word or short phrase, so you don't have to "undo" them mid paragraph. The modal commands are more useful when you want the selection to apply to an entire group, such as when renewing the \maketitle command.

    – Andrew Ho-Lee Feb 16 '11 at 15:06
11
\subsection{The {\ttfamily synchronized} keyword}
\subsection{The \texttt{synchronized} keyword}
  • 2
    It is perhaps pointing out that while each \textXX{bla} has a {\XX(shape/family/series) bla} counterpart, they are not strictly equivalent in all cases: \textit{} automatically takes care of italic correction, while {\itshape } does not. Compare the results of Is {\itshape Puff} a magic dragon? and Is \textit{Puff} a magic dragon?. In general, the \textXX should be used when a single word or a short phrase needs a different font, while the declaration forms should be used for larger pieces of text (usually within an environment). – Villemoes Feb 16 '11 at 05:05
  • 1
    \itshape is far different to all other ... but we were talking about typewriter ... ;-) –  Feb 16 '11 at 08:35