我正在使用 beamer 类,我想在幻灯片中添加一个图形,但是我一直收到此错误:
! Illegal parameter number in definition of \iterate.
<to be read again>
1
l.229 \end{frame}
?
这是我的代码:
\begin{frame}
\begin{figure}
\centering
\begin{tikzpicture}[
node distance = 0pt,
shorten <>/.style = {shorten <=#1, shorten >=#1},
start chain = going right,
box/.style = {shape=rectangle, draw, fill=#1,
minimum width=6mm, minimum height=9mm, outer sep=0pt,
node contents={},
on chain},
box/.default = none,
arrow/.style = {draw=blue!60!black, thick, shorten <>=1mm,
out=90, in=90, looseness=3,
-{Straight Barb[bend]}},
arbox/.style = {inner sep=0pt, minimum size=5pt},
%crbox/.style = {inner sep=0pt,
% node contents={\scriptsize\color{red}$\boldsymbol{\times}$}
% },
label distance = -3pt,
sx/.style = {xshift=#1pt}
]
\node (n0) [box,dashed];
\foreach \i in {1,2,3}
\ifnum\i<1
\node (n\i) [box]
\else
\node (n\i) [box=gray!25]
\fi;
\node (n14) [box,dashed];
\draw[ultra thick,dotted,shorten <=1mm] (n0) -- + (-9mm,0mm);
\draw[ultra thick,dotted,shorten <=1mm] (n14) -- + (+9mm,0mm);
%\fill[black!75]
\end{tikzpicture}
\end{figure}
\end{frame}
我不太清楚为什么框架内的数字会产生问题?如果有人能帮助我,我将不胜感激。
答案1
环境frame
是通过多次将其内容分配给宏来实现的。在此过程中, 被#
解释。因此,要#
在 中使用frame
,您必须将每个 替换#
为####
:
\begin{frame}
\begin{figure}
\centering
\begin{tikzpicture}[
node distance = 0pt,
shorten <>/.style = {shorten <=####1, shorten >=####1},
start chain = going right,
box/.style = {shape=rectangle, draw, fill=####1,
minimum width=6mm, minimum height=9mm, outer sep=0pt,
node contents={},
on chain},
box/.default = none,
arrow/.style = {draw=blue!60!black, thick, shorten <>=1mm,
out=90, in=90, looseness=3,
-{Straight Barb[bend]}},
arbox/.style = {inner sep=0pt, minimum size=5pt},
%crbox/.style = {inner sep=0pt,
% node contents={\scriptsize\color{red}$\boldsymbol{\times}$}
% },
label distance = -3pt,
sx/.style = {xshift=####1pt}
]
\node (n0) [box,dashed];
\foreach \i in {1,2,3}
\ifnum\i<1
\node (n\i) [box]
\else
\node (n\i) [box=gray!25]
\fi;
\node (n14) [box,dashed];
\draw[ultra thick,dotted,shorten <=1mm] (n0) -- + (-9mm,0mm);
\draw[ultra thick,dotted,shorten <=1mm] (n14) -- + (+9mm,0mm);
\end{tikzpicture}
\end{figure}
\end{frame}
答案2
如果您的框架中包含易碎内容,例如 tikz 图片,请使用框架fragile
选项。
您也不需要,\centering
因为图形在投影仪中默认居中。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{frame}[fragile]
\begin{figure}
%\centering
\begin{tikzpicture}[
node distance = 0pt,
shorten <>/.style = {shorten <=#1, shorten >=#1},
start chain = going right,
box/.style = {shape=rectangle, draw, fill=#1,
minimum width=6mm, minimum height=9mm, outer sep=0pt,
node contents={},
on chain},
box/.default = none,
arrow/.style = {draw=blue!60!black, thick, shorten <>=1mm,
out=90, in=90, looseness=3,
-{Straight Barb[bend]}},
arbox/.style = {inner sep=0pt, minimum size=5pt},
%crbox/.style = {inner sep=0pt,
% node contents={\scriptsize\color{red}$\boldsymbol{\times}$}
% },
label distance = -3pt,
sx/.style = {xshift=#1pt}
]
\node (n0) [box,dashed];
\foreach \i in {1,2,3}
\ifnum\i<1
\node (n\i) [box]
\else
\node (n\i) [box=gray!25]
\fi;
\node (n14) [box,dashed];
\draw[ultra thick,dotted,shorten <=1mm] (n0) -- + (-9mm,0mm);
\draw[ultra thick,dotted,shorten <=1mm] (n14) -- + (+9mm,0mm);
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}