1

I have the following aligned equation set

\begin{subequations}\label{1}
\begin{align}
&A=B=C\label{a}\\
&D=E=F\label{b}
\end{align}}
\end{subequations}

I want to put the part

A=B

D=E

In a single box, leaving the

=C

and

=F

out of the box.

Can this be done, using empheq, for example?

2
  • sorry, there should be \\ after label{a}
    – Ehud
    Sep 20, 2017 at 19:46
  • Please check this answer: tex.stackexchange.com/a/389332/120578 if you put a \tikzmark before A and another one after E you got it.
    – koleygr
    Sep 20, 2017 at 19:50

2 Answers 2

3

A short code with pstricks. I define the first =sign in each row as nodes, and I join them with the \ncbox node connection, with the relevant parameters:

\documentclass[svgnames]{article}
\usepackage{amsmath}

\usepackage{pst-node}
\usepackage{auto-pst-pdf} %% for pdflatex compilation

\begin{document}

\begin{subequations}\label{1}
\begin{postscript}
\begin{align}
A& \mathrel{\Rnode{beg}{=}}B=C\label{a}\\
D & \mathrel{\Rnode{end}{=}}E=F\label{b}
\end{align}
\ncbox[boxsize=0.57, nodesepA=1.5ex, nodesepB=0.8ex, linecolor=IndianRed]{beg}{end}
\end{postscript}
\end{subequations}

\end{document} 

enter image description here

1
  • such a great answer by using PSTricks...
    – MadyYuvi
    Sep 21, 2017 at 11:30
3

This is the code :

\documentclass{article}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{calc,shapes}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawRect}[3]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[#3] ([yshift=8pt,xshift=4pt]#1.north west) rectangle ([yshift=0pt,xshift=-4pt]#2.south east);
  \end{tikzpicture}
}

\begin{document}

\begin{subequations}\label{1}
\begin{align}
&\tikzmark{Begin}A=B=C\label{a}\\
&D=E\tikzmark{End}=F\label{b}
\end{align}
\end{subequations}
\DrawRect{Begin}{End}{green}
\end{document}

And the output:

enter image description here

Edit for more complicated situations:

\documentclass{article}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\makeatletter
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture] \node[xshift={\f@size/1.5},yshift={\f@size/3}] (#1) {\phantom{$#2$}};}
\makeatother

% #1 is the draw option (can contain decorate etc) #2 can be any shift option to be used for all points. #3 are the points in comma separated list. 
\def\DrawComplic#1#2#3{
\begin{tikzpicture}[overlay,remember picture]
   \draw[#1]\foreach \point[count=\i from 0] in {#3}{%
   \ifnum\i=0 ([#2]\point) \else --([#2]\point)\fi%
   }--cycle;
\end{tikzpicture}

}
\begin{document}

\begin{subequations}\label{1}
\begin{align}
f(x,y,z)&=\tikzmark{First}{A x}A x=B y=C z\label{a}\\
&=\tikzmark{Fourth}{D x}D x=\tikzmark{Third}{E y}E y=F z\label{b}\\
&=\tikzmark{Last}{F x}F x=G y\label{c}
\end{align}
\end{subequations}
\DrawComplic{red}{}{First.north west,First.north east,First.south east,Third.north east,Third.south east,Last.north east, Last.south east, Last.south west}
 \end{document}

Output:

enter image description here

2
  • Actually my expressions are much more complicated and I need a command that will adapt to any expression
    – Ehud
    Sep 21, 2017 at 4:14
  • @Ehud: I think your answer is been answered for the way it asked and it may be useful for other users later. You have two answers that both solves the problem. If you need something more complicated feel free to open a new answer or at least to edit this one (even if I feel that this will be useful to other people...) [For this reason I suggest If you will not open a new question to make an "Edit" below the original question]. A also added some code for more complicated examples.
    – koleygr
    Sep 21, 2017 at 11:19

You must log in to answer this question.

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