
想要复刻如图所示这种带虚线的边框和上下箭头,我的代码如下:
$\arraycolsep=1pt
\begin{array}{*1l@{\hskip\arraycolsep}c@{\hskip\arraycolsep}*{12}{>{\textstyle}l}}
x^3 & + & 2^3 & = (& x & + & 2) (& x^2 & - & x &\cdot& 2 & + & 2^2) \\
\bigg\updownarrow & & \bigg\updownarrow & & \bigg\updownarrow & & \bigg\updownarrow & \bigg\updownarrow & & \bigg\updownarrow & &\bigg\updownarrow & & \bigg\updownarrow \\
a^3 & + & b^3 & = (&a & + & b) (& a^2 & - & a&\cdot& b & + & b^2)
\end{array}$实现效果

请教,如何实现带虚线的边框?
如果只是要给公式加虚线框,可以直接使用texdoc dashbox(可以参见这里).
但你这个具体的例子中,有较为严格的对齐关系,且对箭头样式似乎也有要求,还是考虑nicematrix:
\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}
\usepackage{tikz}
\newcommand{\myarrow}[1][.75]{\tikz\draw[latex-latex,semithick](0,0)--(0,#1);}
\begin{document}
before $\begin{NiceArray}[c]{@{}*{18}{c@{}}}
x^3 & \,+\, & 2^3 & \;=\; & ( & x & \,+\, & 2 & ) & ( & x^2 & \,-\, & x & \,\cdot\,& 2 & \,+\, & 2^2 & ) \\
\myarrow & & \myarrow & & & \myarrow & & \myarrow & & & \myarrow & & \myarrow & & \myarrow & &\myarrow\\[-1pt]
a^3 & \,+\, & b^3 & \;=\; & ( & a & \,+\, & b & ) & ( & a^2 & \,-\, & a &\,\cdot\, & b & \,+\, & b^2 & )
\CodeAfter
\tikz[line cap=round]
\draw[densely dotted,semithick]
([xshift=-.6em]2-1.west) rectangle ([shift={(.2em,-1ex)}]3-3.south east)
([xshift=-.8em]2-6.west) rectangle ([shift={(.6em,-1ex)}]3-17.south east)
;
\end{NiceArray}$ after
\end{document}注意其中对「原子」间距的微调。另外最好给完整代码,避免别人需要根据代码猜测导言区使用了什么包,减轻潜在回答者的负担。
