TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Also have a look here for a similar question. – Hendrik Vogt Feb 16 '11 at 12:00
up vote 18 down vote accepted

The LaTeX command is \texttt for a teletype font:

\subsection{The \texttt{synchronised} keyword}
share|improve this answer
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
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
\subsection{The {\ttfamily synchronized} keyword}
\subsection{The \texttt{synchronized} keyword}
share|improve this answer
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
\itshape is far different to all other ... but we were talking about typewriter ... ;-) – Herbert Feb 16 '11 at 8:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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