# Tcolorbox inside align environement

I wonder if it's possible to align the coloured equal signs. I have used tcolorboxes between align environments. I doubt so but, is there a way of using tcolorboxes within an align environement? Would it be possible to tell a second align environment to resume a previous one?

\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}

\newtcolorbox{AuxCalc}{
notitle,
colframe=black!75!white,
colback=black!20!white
}

\newtcolorbox{AuxCalc2}{
notitle,
colframe=black!75!white,
colback=black!10!white
}

\begin{document}

\begin{align*}
1 &= 2 \\
1 &= 2 \\
\end{align*}

\begin{AuxCalc}

\begin{align*}
14312 &= 2 \\
1 &= 12342 \\
\end{align*}

\begin{AuxCalc2}
\begin{align*}
1 &= 2 \\
1 &= 2 \\
\end{align*}
\end{AuxCalc2}

\begin{align*}
11235132 &= 2 \\
123513251 &= 2 \\
\end{align*}

\end{AuxCalc}

\begin{align*}
12341 &= 2 \\
112512351 &= 2 \\
\end{align*}

\end{document}


• You should try to play with the TikZ library tikzmark. Apr 12, 2021 at 19:11

Not a particularly attractive approach, but it amounts to studying the areas you want aligned, in search of the widest left-side component and widest right-side component. You save those components with \savewidel and \savewider. Then, for every align type environment you wish to conform to overall alignment, if it does not already possess the widest left/right elements, you call one argument from the left and/or right sides of the environment into \setwidel and \setwider, which basically places the argument in a box the "widel" or "wider" width, with proper right or left alignment.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}

\newtcolorbox{AuxCalc}{
notitle,
colframe=black!75!white,
colback=black!20!white
}

\newtcolorbox{AuxCalc2}{
notitle,
colframe=black!75!white,
colback=black!10!white
}

\begin{document}

\newsavebox\widemathl
\newsavebox\widemathr
\newcommand\savewidel[1]{\savebox\widemathl{$\displaystyle#1$}}
\newcommand\savewider[1]{\savebox\widemathr{$\displaystyle#1$}}
\newcommand\setwidel[1]{\makebox[\wd\widemathl][r]{$#1$}}
\newcommand\setwider[1]{\makebox[\wd\widemathr][l]{$#1$}}

\savewidel{123513251}
\savewider{12342}

\begin{align*}
\setwidel{1} &= \setwider{2} \\
1 &= 2 \\
\end{align*}

\begin{AuxCalc}

\begin{align*}
\setwidel{14312} &= 2 \\
1 &= 12342 \\% <-- HERE IS WIDEMATHR
\end{align*}

\begin{AuxCalc2}
\begin{align*}
\setwidel{1} &= \setwider{2} \\
1 &= 2 \\
\end{align*}
\end{AuxCalc2}

\begin{align*}
11235132 &= \setwider{2} \\
123513251 &= 2 \\% <-- HERE IS WIDEMATHL
\end{align*}

\end{AuxCalc}

\begin{align*}
12341 &= \setwider{2} \\
112512351 &= 2 \\% <-- HERE IS ALSO WIDEMATHL
\end{align*}

\end{document}


• Hi, thank you for your reply!. Although I wouldn't use this while taking notes on the fly, it still simple enought (for a new user like me) so I can use it for more formal texts. I have one question thought: after defining all new commands in the preamble, I can use the \samewide command with different arguments before each different box in the same document, right? Apr 13, 2021 at 16:38
• @MarcoCiafa Yes, for each new block of equations you want aligned, you should be able to reuse the saveboxes employed by \savewidel and \savewider. Apr 13, 2021 at 16:51
• I see there were 2 bookmarks on this question so I will wait some days before accepting your answer. Althoguh, I'm happy with it. Thank you again. Apr 13, 2021 at 20:34