# How can I use \\ with \texttt inside a node?

Take the following MWE:

I made this node with tikz using the normal font:

However, I need to use a monospaced font to get the following result:

Since the node has two lines of text, I would normally do \texttt{line1\\line2}. However when I compile it I get lots of errors.

If I do \texttt{line1}\\\texttt{line2} it compiles with no errors.

Why can't I use \\ inside \texttt{}? Is there a solution to avoid putting \texttt{} on every line of text?

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node[draw,rectangle,align=center] {line1\\line2};
\end{tikzpicture}
\end{document}
• Try {\ttfamily text1\\ text2} Jan 18 '17 at 20:35
• Why not \node[draw,rectangle,align=center,font=\ttfamily] {line1\\line2};? Jan 18 '17 at 20:36
• @Sigur I tried that already, but it only affects to the first line of text. The second line remains with the normal font. Jan 18 '17 at 20:37
• Primarily this is similar to Manual/automatic line breaks and text alignment in TikZ nodes
– Werner
Jan 18 '17 at 22:12