2

In the code below, my aboxed block is misaligned and also of a different size font than the normal text. Can you help me re-align the aboxed block with the above line and also correct the size of the text?

Here is the code:

\documentclass[11pt,fleqn]{book}

\usepackage{xcolor}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage[framemethod=default]{mdframed}
\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={
  colback=blue!15,
  colframe=blue!65,
  }
}
\newenvironment{spread}[1]{%
  \advance\jot#1% indeed
  }{%
\ignorespacesafterend
}

\makeatletter
\patchcmd{\@Aboxed}{\boxed{#1#2}}{\colorbox{red!15}{$#1#2$}}{}{}%
\makeatother

\begin{document}

Solving for $Y_{3}$, we have
\begin{spread}{5pt}
\begin{tcolorbox}[ams align,myformula]
Y_{3}&=\frac{\dfrac{1+sC_{2}R_{2}}{R_{1}R_{2}}}{\dfrac{1+sC_{2}R_{2}}{R_{2}}+\dfrac{1}{R_{1}}+sC_{3}}\nonumber\\
&=\Aboxed{\frac{1+sC_{2}R_{2}}{R_{1}+sC_{2}R_{1}R_{2}+R_{2}+sC_{3}R_{1}R_{2}}}
\end{tcolorbox}
\end{spread}

\end{document} 
  • 2
    \Aboxed basically stands for aligned box thus it emits an & which messes up your alignment. You might need to just use the normal \boxed here (an amsmath construction). Plus in your patching, the contents is forced into text-math mode, thus the cramped size – daleif Dec 8 '15 at 21:10
  • 1
    The intended use of \Aboxed is \Aboxed{x &= y}, i.e. making a box that crosses an alignment. Use it as intended, and it works, but I'm not sure if that's what you want. – Torbjørn T. Dec 8 '15 at 21:23
  • @TorbjørnT. do you know if there is a math aware equivalent of \colorbox? I.e. that knows about the various modes? – daleif Dec 8 '15 at 21:36
  • @TorbjørnT., your solution partially works. How do I get the font in the Aboxed to show up the correct size? – Joe Dec 8 '15 at 21:43
  • 1
    @daleif No idea. Joe: \displaystyle. I can add an answer. – Torbjørn T. Dec 8 '15 at 21:43
4

The intended use of \Aboxed is \Aboxed{x &= y}, i.e. making a box that crosses an alignment. Use it like this and the alignment is correct, though the equals sign of course is included in the box as well. To get the size correct, add \displaystyle in the patch, cf. Show inline math as if it were display math.

Also, you're reinventing the wheel with the spread environment, mathtools already defines the spreadlines environment, which does a similar job. (Only setting \jot instead of adding to it.)

enter image description here

\documentclass[11pt,fleqn]{book}

\usepackage{xcolor}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage[framemethod=default]{mdframed}
\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={
  colback=blue!15,
  colframe=blue!65,
  }
}

\makeatletter
\patchcmd{\@Aboxed}{\boxed{#1#2}}{\colorbox{red!15}{$\displaystyle #1#2$}}{}{}%
\makeatother

\begin{document}

Solving for $Y_{3}$, we have
\begin{spreadlines}{8pt}
\begin{tcolorbox}[ams align,myformula]
Y_{3}&=\frac{\dfrac{1+sC_{2}R_{2}}{R_{1}R_{2}}}{\dfrac{1+sC_{2}R_{2}}{R_{2}}+\dfrac{1}{R_{1}}+sC_{3}}\nonumber\\
\Aboxed{&=\frac{1+sC_{2}R_{2}}{R_{1}+sC_{2}R_{1}R_{2}+R_{2}+sC_{3}R_{1}R_{2}}}
\end{tcolorbox}
\end{spreadlines}

\end{document} 
1

I know I'm late to this solution, but I had the same problem and found this question already asked on stackexchange. Although it does not include a fancy color box, my solution to the misalignment problem is to add an empty group to the left hand side of the \Aboxed command.

Here's a MWE:

\documentclass[]{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
\begin{align*}
\frac{d}{dx} (2+x)e^{-x^2} &= e^{-x^2}\frac{d}{dx} (2+x) + (2+x)\frac{d}{dx} e^{-x^2} & \text{(Product Rule)}\\
\Aboxed{{} &=-(2x^2+4x-1)e^{-x^2}}
\end{align*}
\end{document}

Since \Aboxed expects its input to be of the form A &= B, putting an empty group is enough to satisfy the requirements.

\Aboxed alignment with empty group

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.