# How can I arrange 3 equations in boxes with arrows like this picture?

Can any one tell me how to make a figure exactly like this picture, with 2 arrows etc.

This is my unsuccessful attempt:

\begin{figure}[ht]
\centering
\begin{minipage}[b]{0.35\linewidth}
\begin{lstlisting}[language=C, frame=single,
xleftmargin=5.0ex,basicstyle=\footnotesize\ttfamily,
numbers=left,stepnumber=0, morekeywords={assert} ]
x=x+y;
if(x!=1){
x=2;
if(z) x++;
}
\end{lstlisting}
\end{minipage}
\begin{minipage}[b]{0.35\linewidth}
\begin{lstlisting}[mathescape % to use mathmode inside listing
,language=C, frame=single,
xleftmargin=5.0ex,basicstyle=\footnotesize\ttfamily,
numbers=left,stepnumber=0, morekeywords={assert} ]
x$_1$=x$_0$+y$_0$;
if(x$_1$!=1){
x$_2$=2;
if(z$_0$) x$_3$=x$_2$+1;
}
\end{lstlisting}
\end{minipage}
\fbox{
\begin{minipage}[b]{0.4\linewidth}
\begin{align*}
x_1 &= x_0 + y_0 \wedge
\\ x_2 &= ((x_1 \neq 1)?2:x_1) \wedge
\\ x_3 &= ((x_1 \neq 1 \wedge z_0)?x_2+1:x_2)
\end{align*}
\end{minipage}
}
\end{figure}


Thank you.

• Please can you name the "THIS"(very vague in word search) figure in Question title as something like equations in box/code snippets in box or any known technical tile for easy searchability of future Users Oct 20, 2013 at 15:16
• Thanks for your comment. I edited, could you please check if the title is OK now?
– sean
Oct 20, 2013 at 15:25
• Thanks for your edit and It looks good,atleast better than "this" :) Oct 20, 2013 at 15:28

The best would be using an align* environment, but lstlistings cannot be used; here's a workaround.

\documentclass{article}
\usepackage{amsmath,listings}

\newcommand{\mt}[1]{\mathtt{#1}} % for typewriter subscript in listings

\lstnewenvironment{qsplisting}[1][] % avoid specifying the same thing several times
{\lstset{
mathescape, % to use mathmode in side listing
language=C,
frame=single,
basicstyle=\footnotesize\ttfamily,
numbers=left,
stepnumber=0,
morekeywords={assert},
#1
}}{}

\newsavebox{\leftlisting}
\newsavebox{\rightlisting}

\begin{document}
\begin{figure}[htp]
\begin{lrbox}{\leftlisting}
\begin{minipage}{0.2\linewidth}
\begin{qsplisting}
x=x+y;
if(x!=1){
x=2;
if(z) x++;
}
\end{qsplisting}
\end{minipage}
\end{lrbox}
\begin{lrbox}{\rightlisting}
\begin{minipage}{0.25\linewidth}
\begin{qsplisting}
x$_\mt{1}$=x$_\mt{0}$+y$_\mt{0}$;
if(x$_\mt{1}$!=1){
x$_\mt{2}$=2;
if(z$_\mt{0}$) x$_\mt{3}$=x$_\mt{2}$+1;
}
\end{qsplisting}
\end{minipage}
\end{lrbox}

\begin{align*}
&\to\boxed{
\begin{aligned}
\mathcal{C}&:=
\!\begin{aligned}[t]
x_1 &= x_0 + y_0 \wedge{} \\
x_2 &= ((x_1 \neq 1)?2:x_1) \wedge{} \\
x_3 &= ((x_1 \neq 1 \wedge z_0)?x_2+1:x_2)
\end{aligned}
\\
\mathcal{P}&:= x_3\le 3
\end{aligned}
}
\end{align*}
\end{figure}
\end{document}


Note: always add the p positioning specifier for figures

• I know I should avoid "thank" comment. But this is really what I need, thank you very much :)
– sean
Oct 20, 2013 at 15:49