我正在尝试将带框的文本作为 tikz 节点的一部分。我找到了一个例子这里我正在尝试遵循,但它给了我一个错误: \@xverbatim 的参数有一个额外的 }。我搞不懂。任何帮助都将不胜感激。我的代码如下。有趣的是,如果我将 documentclass 更改为 article,它就会起作用。但是,我需要在 beamer 环境中使用它。
\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}
答案1
您必须添加[fragile]
选项\begin{frame}
。我还将选项添加font=\tiny,text width=0.45\textwidth
到mybox
样式中。
代码:
\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}
下面是另一个选项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}