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?

21

The LaTeX command is \texttt for a teletype font:

\subsection{The \texttt{synchronised} keyword}
  • 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 Arnold Feb 16 '11 at 14:20
  • 1
    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 Feb 16 '11 at 15:06
  • See also this related question. – Andrew Ho Feb 16 '11 at 15:23
11
\subsection{The {\ttfamily synchronized} keyword}
\subsection{The \texttt{synchronized} keyword}
  • 1
    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 5:05
  • 1
    \itshape is far different to all other ... but we were talking about typewriter ... ;-) – user2478 Feb 16 '11 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.