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 use TikZ in beamer to point to a line of code. Here's what I have so far:

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

\begin{document}

\begin{frame}[fragile,t] 
\frametitle{test}
\begin{Verbatim}
example code 
lines
\end{Verbatim}
\tikz \node [circle,fill=black] {};
\begin{Verbatim}
here 
\end{Verbatim}
\end{frame}

\end{document}

The node, however, appears on a new line. I want to put it on the right of the line saying, "lines" so that I can then use TikZ overlays to point an arrow to it and put some explanatory lines on the right.

I have seen examples of this but they either use math or plain text. How can I do this with Verbatim?

share|improve this question
add comment

1 Answer

up vote 14 down vote accepted

You need to use commandchars. In my example |replaces \. §and !are used to replace the accolades {and }

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

\begin{document}
 \def\firstnode{\tikz[remember picture] \node[circle,fill=blue] (n1) {};}  
 \def\secondnode{\tikz[remember picture] \node[circle,fill=red] (n2) {};} 

\begin{frame}[fragile,t] 
\frametitle{test} 

\begin{Verbatim} [commandchars=\|\§\! ]
example code 
lines here |firstnode  
\end{Verbatim}

\begin{Verbatim}[commandchars=\|\§\! ]      
 |secondnode   Explanation
\end{Verbatim} 

 \begin{tikzpicture}[remember picture,overlay]
        \path[->,line width=1pt,dashed,red!40,>=latex] (n1) edge [bend left] (n2);
\end{tikzpicture} 
\end{frame}     
\end{document} 

enter image description here

share|improve this answer
    
Works like a charm. just one follow-up though. How do I insert that weird snake-like symbol? Can I use another one in its place? –  recluze Nov 20 '11 at 10:17
    
@recluze You can use the symbol that you want. Examples in Latex Companion use [ and ]. The most important here is | –  Alain Matthes Nov 20 '11 at 10:28
    
Great. A +1 for the output :) –  recluze Nov 20 '11 at 10:30
    
taking inspiration from this great answer, I made a little variation: instead of doing \def..., I have the following \newcommand{\mytikzrefnode}[1]{\tikz[remember picture,baseline=-.5ex] \coordinate (#1) {};}, which allows me to do \mytikzrefnode{n1} –  MarcoS Mar 11 '13 at 21:21
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.