我怎样才能将 3 个方程式排列在像这张图片一样带有箭头的框中?

我怎样才能将 3 个方程式排列在像这张图片一样带有箭头的框中?

谁能告诉我如何制作一个与这张图完全一样的图形,带有 2 个箭头等等?

这张照片

这是我失败的尝试:

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

谢谢。

答案1

最好的办法是使用align*环境,但lstlistings无法使用;这里有一个解决方法。

\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*}
& \usebox{\leftlisting} \quad\to\quad \usebox{\rightlisting} \\
&\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}

注意:始终p为图形添加定位说明符

在此处输入图片描述

相关内容