I'd really like to do exactly what's being asked for in this question: Highlight an equation within an align environment, but with the ability to change the color when I call it, so that I could have one equation highlighted yellow, the next one highlighted lime, a third highlighted magenta, and a fourth highlighted yellow again, etc. (I'd also like the frame to be the same color as the highlight, but I'm pretty sure I can figure that part out. :) ) I really like the first solution - the one with 15 votes - and would love to know how to tweak that one to do what I want - something like \alignedbox[yellow].

I'm not including a MWE since my question is just a follow-up to a previous one, but I can if it would be helpful.

I don't know if it's relevant or helpful, but what I'm doing right now is just using this that I found but don't really understand:


and then using \phantom{} and \quad and such to try to get the horizontal spacing right so that things align the way I want. :)


2 Answers 2


You can just add one more parameter to the macro. Below I have made the first parameter to specify the color -- it is optional and defaults to yellow if not provided as in the first example:

enter image description here




  % #1 = color (optional, defaults to yellow)
  % #2 = before alignment
  % #3 = after alignment
  \settowidth\dlf{$\displaystyle #2$}
  \fcolorbox{red}{#1}{$\displaystyle #2 #3$}

    \alignedbox{a}{=b} &                        c  &= d \\
                c &= d & \alignedbox[magenta!20]{i}{=k} \\
                e &= f &                        g  &= h  
  • Thank you! That's exactly what I needed. Thanks to your comments in the code above, I also now understand how to deal with parameters in a '\newcommand'. (I had already upvoted the answer to the one you and I both referenced, so I upvoted this one as well.) Thanks again!
    – Keila
    Sep 17, 2012 at 0:14
  • 1
    It doesn't support multi-line equations in align environment
    – smh
    Dec 18, 2012 at 20:36

Another possibility is to exploit the hf-tikz package.

A couple of examples:


     \tikzmarkin[fill=yellow]{first eq}a &= b\tikzmarkend{first eq} &          c  &= d \\
      c &= d &         i &= k \\
     \tikzmarkin{second eq}e &= f\tikzmarkend{second eq} &          \hfsetbordercolor{blue}\tikzmarkin[top color=white, bottom color=blue!20]{third eq}g  &= h\tikzmarkend{third eq}  

which give the following result:

enter image description here


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.