# Box around one or multiple equations using tcolorbox

I want to put (1) a box around 1 equation inside an align environment, and also (2) a box around all equations in align environment. I'm already using tcolorbox and would like to use that. I have tried boxing all equations with tcolorbox but the problem is that it goes page-wide which I don't like, and also leaves a visible margin above the first equation. I want to keep equation numbers out of the box as well. Any suggestions?

Edit: Thanks for pointing me to a solution. The problem, however, is that all the solutions use another math environment (either within tcolorbox or empheq package). I am using a very specialized align environment and hence have to have a box without tcolorbox or empheq equation style.

So I want a box around align equations without leaving \begin{align} and \end{align} environment.

Edit2: Here is the MWE code.

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{flalign}

\begin{gathered}

A \quad  \vphantom{\sum \limits _{n=0} ^{N-1}} \\

B \quad ~~ \vphantom{\sum \limits _{n=0} ^{N-1}}

\end{gathered}

&&

\begin{aligned}\label{equationAB}

A\: &= \sum \limits _{n=0} ^{N-1} a[n]\\

B &= \sum \limits _{n=0} ^{N-1} b[n]

\end{aligned}

&&

\end{flalign}

\end{document}

• Please, show us your code. It is extremely unclear from your question what you have done and what you want to do. Any answer risk turning out to be useless. – cfr Nov 18 '15 at 2:10
• Does this help you? tex.stackexchange.com/a/237855/1952 or tex.stackexchange.com/a/240327/1952 – Ignasi Nov 18 '15 at 8:46
• The first link is really what I want, except that the box be around the actual equations and equations numbers be outside the box. – Qasim Chaudhari Nov 19 '15 at 2:24
• @QasimChaudhari: The tcolorbox solution with tcbhighmath should be what you request, in my point of view. Any tcolorbox can be configured to match top etc. spacing, background colour, frame style etc. – user31729 Dec 27 '15 at 8:53
• @ChristianHupfer, how can I raise this question from dead after editing it? @ Ignasi, your solution helps but when using align equations, equation numbers are included. I want something like the first equation (number outside box) but with align environment. Thanks. – Qasim Chaudhari Apr 21 '16 at 15:29

I give a try with tcolorbox. Are you looking for the following?

The code puts a \tcbhighmath box around the aligned equations:

\documentclass{article}

\usepackage{amsmath}
\usepackage[many]{tcolorbox}

\begin{document}
\begin{flalign}
\begin{gathered}
A \quad  \vphantom{\sum \limits _{n=0} ^{N-1}} \\
B \quad ~~ \vphantom{\sum \limits _{n=0} ^{N-1}}
\end{gathered}
&&
\tcbhighmath{\begin{aligned}\label{equationAB}
A\: &= \sum \limits _{n=0} ^{N-1} a[n]\\
B &= \sum \limits _{n=0} ^{N-1} b[n]
\end{aligned}}
&&
\end{flalign}
\end{document}

• @ThomasSturm. For some strange reason, it is producing a yellow background in my office computer but when I compile at home computer, it has a pink background. How can I have it yellow consistently? – Qasim Chaudhari May 12 '16 at 3:24
• @QasimChaudhari There should be no difference. But you can change the coloring locally like \tcbhighmath[colback=yellow]{... or setting highlight math style globally (page 335 of the documentation v3.91). – Thomas F. Sturm May 12 '16 at 10:44

I think what you want is not possible with tcolorbox because you should change the environment, but you can always use tikzmark or hf-tikz which can draw boxes around any part of your text.

Next code shows how to use hf-tikz commands tikzmarkin and tikzmarkend. Both commands are defined like

\tikzmarkin{marker-id}(below right offset)(above left offset)
\tikzmarkend{marker-id}


marker-id is a label which is unique in every document and offsets are optional arguments to better adjust box size.

\documentclass{article}
\usepackage{amsmath}
\usepackage{hf-tikz}

\begin{document}

\begin{flalign}
\begin{gathered}
A \quad \vphantom{\sum \limits _{n=0} ^{N-1}} \\
B \quad ~~ \vphantom{\sum \limits _{n=0} ^{N-1}}
\end{gathered}
&&
\begin{aligned}\label{equationAB}
\tikzmarkin{a}(1,-1)(-1,1) A\: &= \sum \limits _{n=0} ^{N-1} a[n]\\
B &= \sum \limits _{n=0} ^{N-1} b[n]\tikzmarkend{a}
\end{aligned}
&&
\end{flalign}
\end{document}