2

I'm working with a system

$$\begin{cases}
Ax+By   & = C\\
Dx+Ey   & = F
\end{cases}$$ 

Is there a way to put a box around A & D, around B & E, and around C & F within the system?

Troy
  • 13,741
  • You could use tikzpicture to print your equation and functionality rememberpictureoverlay and then you can add boxes arrows, symbols... whatever you want to make it appear as you wish – koleygr Sep 01 '17 at 07:22
  • 1
    As always: also don't use $$...$$ that is not LaTeX syntax – daleif Sep 01 '17 at 07:25
  • I'm not sure what you mean. In my TeXworks $$...$$ is the math display environment. – Ryan Sep 01 '17 at 07:56
  • 3
    $$ is primitive tex syntax but it should not be used in a latex document. see https://tex.stackexchange.com/a/69854/1090 – David Carlisle Sep 01 '17 at 08:03
  • See my answer: I using \[ and \] to have what you want. This is what @DavidCarlisle says – koleygr Sep 01 '17 at 08:05

1 Answers1

6

Edit:

\documentclass{article}
\usepackage{amsmath}

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

\makeatletter
\xdef\myfsize{\f@size}
\makeatother



\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawRect}[4]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[#3] ([yshift={\myfsize/1.5},xshift=#4]#1.north west) rectangle ([xshift=-#4]#2.south east);
  \end{tikzpicture}
}
\begin{document}
\[\begin{cases}
\tikzmark{a}A x+ \tikzmark{c}B y   & = \tikzmark{e} C\\
D\tikzmark{b} x+E\tikzmark{d} y   & = F\tikzmark{f}
\DrawRect{a}{b}{green}{4pt}\DrawRect{c}{d}{red}{4pt}\DrawRect{e}{f}{black}{4pt}
\end{cases}
\]
\end{document}

The above gives the same results but finds automatically the fontsize to use it as yshift and has an extra argument that reduces the box on x axis (a negative value will increase it)

Source of code that I changed: https://tex.stackexchange.com/a/35718/120578

Old answer A fast solution:

\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{cases}
\tikzmark{a} A x+ \tikzmark{c} B y   & = \tikzmark{e} C\\
D \tikzmark{b} x+E\tikzmark{d} y   & = F\tikzmark{f}
\DrawRect{a}{b}{green}\DrawRect{c}{d}{red}\DrawRect{e}{f}{black}
\end{cases}
\]
\end{document}

Can be improved but I adding it to get my comment's point.

Result:

enter image description here

koleygr
  • 20,105