5

Possible Duplicate:
Problem with TikZ, beamer and verbatim

Is it possible to use verbatim-like environments inside a tikz node? This MWE gives an error:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\tikz{
  \node{\begin{verbatim}a_b\end{verbatim}};
}
\end{document}
Mohan
  • 15,906

2 Answers2

7

I get missing item error with your MWE. However, it seems to work with listings package. If you would allow it, then try the code below.

\documentclass{article}
\usepackage{tikz}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}

\tikz
\node at (0,0) {
\begin{lstlisting}
a_b
\end{lstlisting}
};

\end{document}
hpesoj626
  • 17,282
2

This other command works for me:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node[draw] at (0,0) {\verb+a_b+};
\end{tikzpicture}
\end{document}
Sigur
  • 37,330