0

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} 
12
  • 1
    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
    Commented Nov 18, 2015 at 2:10
  • 4
    Does this help you? tex.stackexchange.com/a/237855/1952 or tex.stackexchange.com/a/240327/1952
    – Ignasi
    Commented Nov 18, 2015 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.
    – QMC
    Commented Nov 19, 2015 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
    Commented Dec 27, 2015 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.
    – QMC
    Commented Apr 21, 2016 at 15:29

2 Answers 2

4

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

enter image description here

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}
4
  • @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?
    – QMC
    Commented May 12, 2016 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). Commented May 12, 2016 at 10:44
  • @ThomasF.Sturm Is it possible to set \tcbhighmath[<my options>] globally in (the preamble)? I would love for all my equation and align environments to be shaded automatically or by default?
    – Raphael
    Commented Jul 21, 2021 at 8:11
  • @Raphael Yes, just adapt highlight math style or highlight math (page 373 of the documentation v4.51) for global effects, e.g. \tcbset{highlight math/.append style={enhanced, drop shadow}} Commented Jul 27, 2021 at 5:46
2

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}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .