1

I need to have three columns and the text within each should be enclosed in a box. below is my code, but it is not working:

\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}

This is what I am getting enter image description here This is what I like to get enter image description here

1 Answer 1

3

If you would like to give the boxing job to tcolorbox, I can provide a solution for the problem. Three boxes with equal width are created by \tcbitem within a tcbitemize environment. The box properties are set by the options of 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}

The result is:

enter image description here

If marks are used, they can be put inside the box. For example:

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .