6

How to box the second split environment ?

Bonus: to box only a part of the split environment content it so I can add a \Longleftrightarrow before the box.

MWE:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
    \begin{split}
        A ={}& B + C + D
    \end{split}\nonumber\\
    \begin{split}
        A ={}& \phantom{{}+{}} B\_is\_long\\
             &            +    C\_is\_long\_too\\
             &            +    D\_is\_long\_too
    \end{split}
\end{align}

\end{document}

MWE: MWE

What I'm looking for : What I want

4 Answers 4

7

You can customize the output, but the idea is simple with hf-tikz.

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

\begin{document}

\begin{align}
A ={}& B + C + D \notag \\
\begin{split}
\tikzmarkin{thisbox}
A ={}& \phantom{{}+{}} B\_is\_long\\
  &            +    C\_is\_long\_too\\
  &            +    D\_is\_long\_too\tikzmarkend{thisbox}
\end{split}
\end{align}

\end{document}

enter image description here

4

I suggest you use aligned instead of split environments, as one can encase an aligned environment -- but not a split environment -- in a \boxed directive.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc} % for longer "underscore" characters
\usepackage{amsmath}

\begin{document}

\begin{align}
    &\kern\fboxsep\kern\fboxrule % take care to align the "A"s
     \begin{aligned}
         A ={}& B + C + D
     \end{aligned}\nonumber\\
    & \boxed{\begin{aligned}
        A ={}& \phantom{{}+{}} B\_is\_long      \\
             &            +    C\_is\_long\_too \\
             &            +    D\_is\_long\_too
    \end{aligned}}
\end{align}

\end{document}
1
  • A follow-up comment: The first of the two aligned environments isn't needed. I didn't remove the redundant code, though, in the answer shown above as I assume that in your real document, the first of two split/aligned environments does serve a useful purpose.
    – Mico
    Dec 18, 2022 at 18:33
2

hope it will help

\documentclass[11pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{empheq}

\begin{document}
\begin{align*}
    \begin{split}
        A ={}& B + C + D
    \end{split}\nonumber\\
\end{align*}

\begin{empheq}[box=\fbox]{align}   
    \begin{split}
        A ={}& \phantom{{}+{}} B\_is\_long\\
             &            +    C\_is\_long\_too\\
             &            +    D\_is\_long\_too
    \end{split}
\end{empheq}
\end{document}

enter image description here

2
  • 1
    alignment with the first = is lost
    – coucou
    Dec 18, 2022 at 14:20
  • 1
    There's also too much space between the two blocks. Dec 18, 2022 at 15:54
2

One way is to overlap blank \boxed{} on top of your expression, which takes the same space as the original expression itself. This can be achieved by both \mathrlap{} (from mathtools) and \phantom{}

enter image description here

\documentclass{article}
\usepackage{mathtools}
\usepackage{xcolor}

\begin{document}
\begin{align}
    \begin{split}
        A ={}& B + C + D
    \end{split}\nonumber\\
  \mathrlap{\boxed{\phantom{\begin{gathered}A = {}+ C\_is\_long\_too\\A\\A\end{gathered}}}}
  \hspace{\dimexpr\fboxsep+\fboxrule-0.4pt}
  \begin{split}
        A ={}& \phantom{{}+{}} B\_is\_long\\
             &            +    C\_is\_long\_too\\
             &            +    D\_is\_long\_too
    \end{split}
\end{align}
\end{document}
2
  • While being an impressive work-out, it's obviously too much complex.
    – coucou
    Dec 18, 2022 at 14:22
  • 1
    @Mico Thanks for pointing at this. I removed misleading and confusing parts.
    – Celdor
    Dec 19, 2022 at 9:18

You must log in to answer this question.

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