# Box in align/array environment -simple way?

I've got the following plain setup:

\usepackage{amsmath, mathtools}
\begin{document}
\begin{align*}
\begin{array}{c c l}
(f^{-1}(y))' =& \frac{1}{f'(f^{-1}(y))}&\text{\tiny $\vert$ step 1}\\ \\
(f^{-1}(y))'' =& \left(\frac{1}{f'(f^{-1}(y))}\right)'&\text{\tiny $\vert$step 2}\\ \\
(f^{-1}(y))'' =& \frac{-1\cdot(f'(f^{-1}(y)))'}{(f'(f^{-1}(y)))^2}&\text{\tiny $\vert$ step 3}\\ \\
(f^{-1}(y))'' =&\frac{-f''(f^{-1}(y))\,(f^{-1}(y))'}{(f'(f^{-1}(y)))^2}&\text{\tiny $\vert$ step 4}\\\\
(f^{-1}(y))'' =& \frac{-f''(f^{-1}(y))}{(f'(f^{-1}(y)))^3}\\
\end{array}
\end{align*}
\end{document}


The result looks quite okay, but I wish to have a box around the last line. \Aboxed doesn't do much since it's ripping the structure apart. I've read some solutions with tikz involved, but I'm not familiar with it.

• you should not be using align here as you only have one row and no alignment also array will give incorrect spacing for = and textstyle not displaystyle, but as you are using array you can use \hline to get the horixontal lines and \multicolumn{1}{|c}{...} to get the left vertical and {c|} to get the right vertical. Commented Apr 24, 2021 at 13:58
– Leon
Commented Apr 24, 2021 at 14:41
• I'm using array for it's nice centering. But I didn't discovered how to place a box still
– Leon
Commented Apr 24, 2021 at 14:43
• array is intended for matrices and arrays, it uses displaystyle and the spacing around =& is quite wrong for an equation, but if you do use array surround ot with $..$ not align Commented Apr 24, 2021 at 15:47

If you really insist on your desired alignment then yes, you might use array, but then there is no reason to use align* outside. The box can be added by the standard LaTeX rule management for tabular/array.

\documentclass{article}

\usepackage{mathtools}
\usepackage{array}

\begin{document}

$\setlength{\extrarowheight}{4ex} \begin{array}{r >{\displaystyle}c l} (f^{-1}(y))' ={}& \frac{1}{f'(f^{-1}(y))} &\text{\tiny \vert step 1}\\ (f^{-1}(y))'' ={}& \left(\frac{1}{f'(f^{-1}(y))}\right)' &\text{\tiny \vert step 2}\\ (f^{-1}(y))'' ={}& \frac{-1\cdot(f'(f^{-1}(y)))'}{(f'(f^{-1}(y)))^2} &\text{\tiny \vert step 3}\\ (f^{-1}(y))'' ={}& \frac{-f''(f^{-1}(y))\,(f^{-1}(y))'}{(f'(f^{-1}(y)))^2} &\text{\tiny \vert step 4}\\[3ex] \cline{1-2} \multicolumn{1}{|r}{(f^{-1}(y))''=} & \multicolumn{1}{c|}{\dfrac{-f''(f^{-1}(y))}{(f'(f^{-1}(y)))^3}} \\[3ex] \cline{1-2} \end{array}$

\end{document}


\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{align*}
(f^{-1}(y))' &= \frac{1}{f'(f^{-1}(y))}\\ \\
(f^{-1}(y))'' &= \left(\frac{1}{f'(f^{-1}(y))}\right)'\\ \\
(f^{-1}(y))'' &= \frac{-1\cdot(f'(f^{-1}(y)))'}{(f'(f^{-1}(y)))^2}\\ \\
(f^{-1}(y))'' &=\frac{-f''(f^{-1}(y))\,(f^{-1}(y))'}{(f'(f^{-1}(y)))^2}\\\\
\Aboxed{(f^{-1}(y))'' &= \frac{-f''(f^{-1}(y))}{(f'(f^{-1}(y)))^3}}\\
\end{align*}

\end{document}

• Well, I actually want the fractions on the right to be centered. That's why I used array-environment
– Leon
Commented Apr 24, 2021 at 14:38

With {NiceArray} of nicematrix.

\documentclass{article}
\usepackage{mathtools}
\usepackage{nicematrix}

\begin{document}

$\setlength{\extrarowheight}{4ex} \setlength{\arraycolsep}{0pt} \begin{NiceArray}{@{\enskip}r>{\displaystyle}c@{\enskip}>{\quad}l} (f^{-1}(y))' ={}& \frac{1}{f'(f^{-1}(y))} &\text{\tiny \vert step 1}\\ (f^{-1}(y))'' ={}& \left(\frac{1}{f'(f^{-1}(y))}\right)' &\text{\tiny \vert step 2}\\ (f^{-1}(y))'' ={}& \frac{-1\cdot(f'(f^{-1}(y)))'}{(f'(f^{-1}(y)))^2} &\text{\tiny \vert step 3}\\ (f^{-1}(y))'' ={}& \frac{-f''(f^{-1}(y))\,(f^{-1}(y))'}{(f'(f^{-1}(y)))^2} &\text{\tiny \vert step 4}\\[3ex] \Block[draw]{1-2}{}% (f^{-1}(y))''={} & \dfrac{-f''(f^{-1}(y))}{(f'(f^{-1}(y)))^3} \\[3ex] \end{NiceArray}$

\end{document}


You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).