[Tex/LaTex] Verbatim inside a minipage inside a tikz node — beamer class

tikz-pgfverbatim

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}

Best Answer

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}