Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to put verbatim text inside a node (in a beamer frame):

\begin{frame}[fragile]{P}
\tikzstyle{cell} = [rectangle, draw, thin , fill=black!10 , minimum size=5mm]
\begin{tikzpicture}[node distance=3cm, auto,>=latex', thick, overlay]
    \path[->,draw]<1-> node[cell] (p) {Text at \verb!p!};                
\end{tikzpicture}
\end{frame}

But it doesn't compile and produces an error. If one replaces \verb!p! with anything else, like "p", it compiles. Note that I also tried to put "fragile" in the frame options. Thank you in advance!

share|improve this question
    
I can't test right now: Does the problem persist when you do the same thing (verbatim in a node) in a "normal" (i.e. article) document class? –  Caramdir Apr 2 '12 at 23:10
    
Do you need verbatim, or can you just write \texttt{p}? –  Torbjørn T. Apr 2 '12 at 23:25
    
thank you all, all solutions were useful for me. –  Leo Rodríguez Apr 3 '12 at 2:23
add comment

1 Answer

up vote 6 down vote accepted

You can use \Verb from the fancyvrb package:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{fancyvrb}
\usetikzlibrary{arrows}

\begin{document}

\begin{frame}[fragile]{P}
\tikzstyle{cell} = [rectangle, draw, thin , fill=black!10 , minimum size=5mm]
\begin{tikzpicture}[node distance=3cm, auto,>=latex', thick, overlay]
    \path[->,draw] node[cell] (p) {Text at \Verb!p!};                
\end{tikzpicture}
\end{frame}

\end{document}

As Caramdir has correctly suspected in a comment, if another document class (article, for example) is used there's no need to use \Verb and the standard \verb command will work.

enter image description here

You should also consider using \texttt{p} instead of \verb!p! (as Torbjørn T suggested in his comment) if your intention is just to use a mono-spaced font for the "p" character.

share|improve this answer
add comment

Your Answer

 
discard

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.