我需要有三列,并且每列中的文本都应包含在一个框中。下面是我的代码,但它不起作用:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\mytikzmark}[1]{\tikz[overlay,remember picture] \node[baseline] (#1) {};}
\begin{document}
\begin{frame}{if/else/elseif}
\begin{columns}[T]
\fcolorbox{black}{white}{
\begin{column}{.3\textwidth}
% Your text here
\textcolor{orange}{IF}
\textcolor{blue}{if} cond
\hspace{10 pt}commands
\textcolor{blue}{end}
\end{column}
}
\begin{column}{.3\textwidth}
% Your text here
\textcolor{orange}{ELSE}
\textcolor{blue}{if} cond
\hspace{10 pt}commands1
\textcolor{blue}{else}
\hspace{10 pt}commands2
\textcolor{blue}{end}
\end{column}
\begin{column}{.3\textwidth}
% Your text here
\textcolor{orange}{ELSEIF}
\textcolor{orange}{ELSE}
\textcolor{blue}{if} cond
\hspace{10 pt}commands1
\textcolor{blue}{elseif} cond2
\hspace{10 pt}commands2
\textcolor{blue}{else}
\hspace{10 pt}commands3
\textcolor{blue}{end}
\end{column}
\end{columns}
\end{frame}
\end{document}
这是我得到的 这是我所希望得到的
答案1
如果您愿意将装箱工作交给,我可以为该问题提供解决方案。在环境中tcolorbox
创建三个宽度相等的盒子。盒子属性由 选项设置:\tcbitem
tcbitemize
tcbitemize
\documentclass{beamer}
\usepackage[skins,raster]{tcolorbox}
\begin{document}
\begin{frame}{if/else/elseif}
\begin{tcbitemize}[enhanced,colback=white,colframe=black,size=fbox,
sharp corners,raster columns=3,raster valign=top,
% raster before skip=0pt,raster after skip=0pt, % glue before/after
]
\tcbitem
% Your text here
{\centering\textcolor{orange}{IF}\par}
\textcolor{blue}{if} cond
\hspace{10 pt}commands
\textcolor{blue}{end}
\tcbitem
% Your text here
{\centering\textcolor{orange}{ELSE}\par}
\textcolor{blue}{if} cond
\hspace{10 pt}commands1
\textcolor{blue}{else}
\hspace{10 pt}commands2
\textcolor{blue}{end}
\tcbitem
% Your text here
{\centering\textcolor{orange}{ELSEIF}\par}
\textcolor{blue}{if} cond
\hspace{10 pt}commands1
\textcolor{blue}{elseif} cond2
\hspace{10 pt}commands2
\textcolor{blue}{else}
\hspace{10 pt}commands3
\textcolor{blue}{end}
\end{tcbitemize}
\end{frame}
\end{document}
结果是:
如果使用标记,可以将其放在框内。例如:
\documentclass{beamer}
\usepackage[skins,raster]{tcolorbox}
\begin{document}
\begin{frame}{if/else/elseif}
\begin{tcbitemize}[enhanced,colback=white,colframe=black,size=fbox,
sharp corners,raster columns=3,raster valign=top,
% raster before skip=0pt,raster after skip=0pt, % glue before/after
]
\tcbitem
% Your text here
{\centering\textcolor{orange}{IF}\par}
\textcolor{blue}{if}\tikz[remember picture,baseline=(a.base)] \node (a) {cond};
\hspace{10 pt}commands
\textcolor{blue}{end}
%
\begin{tikzpicture}[remember picture,overlay]
\node[align=left,font=\small] (x) at (1,-1.2)
{Conditional statement:\\ evaluates to true or false};
\draw[->] (x)--(a);
\end{tikzpicture}%
%
\tcbitem
% Your text here
{\centering\textcolor{orange}{ELSE}\par}
\textcolor{blue}{if} cond
\hspace{10 pt}commands1
\textcolor{blue}{else}
\hspace{10 pt}commands2
\textcolor{blue}{end}
\tcbitem
% Your text here
{\centering\textcolor{orange}{ELSEIF}\par}
\textcolor{blue}{if} cond
\hspace{10 pt}commands1
\textcolor{blue}{elseif} cond2
\hspace{10 pt}commands2
\textcolor{blue}{else}
\hspace{10 pt}commands3
\textcolor{blue}{end}
\end{tcbitemize}
\end{frame}
\end{document}