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 am trying to get a boxed text as part of a tikz node. I found an example here that I am trying to follow, but it is giving me an error: Argument of \@xverbatim has an extra }. I can't figure it out. Any help would be greatly appreciated. My code is below. One interesting thing is that if I change the documentclass to article, it works. However, I need this in a beamer environment.

\documentclass[table,xcolor=pdftex,dvipsnames]{beamer}

\usepackage{tikz}

\usetikzlibrary{shapes,snakes}

\begin{document}

\begin{frame}
   \frametitle{Testing verbatim}
   \tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
    rectangle, rounded corners, inner sep=2pt, inner ysep=2pt]
\begin{tikzpicture}
\node [mybox] (box){%
    \begin{minipage}{0.4\textwidth}
    \tiny
    \begin{verbatim}
<list title="MOVIES">
   <film>
      <title>The Shining</title>
      <release_date>1980-05-23</release_date>
      <director>Stanley Kubrick</director>
      <actor>Jack Nicholson</actor>
   </film>
   <film>
      <title>Spartacus</title>
      <director>Stanley Kubrick</director>
   </film>
   <film>
      <title>The Passenger</title>
      <actor>Jack Nicholson</actor>
   </film>
   ...
</list>
    \end{verbatim}
    \end{minipage}
};
\end{tikzpicture}  
\end{frame}
\end{document}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

You have to add [fragile] option to \begin{frame}. I have also added the options font=\tiny,text width=0.45\textwidth to the mybox style.

Code:

\documentclass[table,xcolor=pdftex,dvipsnames]{beamer}

\usepackage{tikz}

\usetikzlibrary{shapes,snakes}

\begin{document}

\begin{frame}[fragile]
   \frametitle{Testing verbatim}
   \tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
    rectangle, rounded corners, inner sep=2pt, inner ysep=2pt,font=\tiny,text width=0.45\textwidth]
\begin{tikzpicture}
\node [mybox] (box){%
    \begin{minipage}{0.4\textwidth}
    \begin{verbatim}
<list title="MOVIES">
   <film>
      <title>The Shining</title>
      <release_date>1980-05-23</release_date>
      <director>Stanley Kubrick</director>
      <actor>Jack Nicholson</actor>
   </film>
   <film>
      <title>Spartacus</title>
      <director>Stanley Kubrick</director>
   </film>
   <film>
      <title>The Passenger</title>
      <actor>Jack Nicholson</actor>
   </film>
   ...
</list>
    \end{verbatim}
    \end{minipage}
};
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

Here is another option with tcolorbox:

\documentclass[table,xcolor=pdftex,dvipsnames]{beamer}

\usepackage{tcolorbox}
\tcbuselibrary{listings,breakable,fitting}

\newtcblisting{myverbatim}{
      arc=3mm,
      top=0mm,
      bottom=0mm,
      left=0mm,
      right=0mm,
      boxrule=1pt,
      colframe=red,
      colback=blue!20,
      listing only,
      listing options={
        basicstyle=\tiny
      },
      hbox,
      %width=0.6\textwidth,  %%For fitting library
      breakable
}

\begin{document}

\begin{frame}[fragile]
   \frametitle{Testing verbatim}
\pause
\begin{myverbatim}
<list title="MOVIES">
   <film>
      <title>The Shining</title>
      <release_date>1980-05-23</release_date>
      <director>Stanley Kubrick</director>
      <actor>Jack Nicholson</actor>
   </film>
   <film>
      <title>Spartacus</title>
      <director>Stanley Kubrick</director>
   </film>
   <film>
      <title>The Passenger</title>
      <actor>Jack Nicholson</actor>
   </film>
   ...
</list>
    \end{myverbatim}
\end{frame}
\end{document}
share|improve this answer
    
Wonderful, thank you very much for your assistance. –  ozsu Aug 13 at 1:39
    
Spoke too soon... I need to put the entire \begin{tikzpicture} ... \end{picture} inside an \only<2>{...}. When I do that I get the error again. I left that part out because I thought that would be simple. Any ideas to fix this please? –  ozsu Aug 13 at 1:53
    
Related:tex.stackexchange.com/questions/55687/… –  JPi Aug 13 at 8:04
    
@ozsu Put a \pause before \begin{tikzpicture}. –  Harish Kumar Aug 13 at 9:57
    
Thank you very much. I would have never thought of it. –  ozsu Aug 13 at 10:34

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.