# Draw rectangle into the Array

My MWE

\documentclass[a4paper,11pt]{article}

\begin{document}
$$\begin{array}{ccccc} 16\cdot I_1 & + & 11\cdot I_2 & =& 13\\ 11\cdot I_1 & + & 16\cdot I_2 & =& 17 \end{array}$$
\end{document}


What I want to do is to draw a rectangular shape to unknown variables and known coefficients. This equation may be 3 or 4 variables. An example figure is below. Is it possible?

I am sure there is a nice tikz way to do this, but here, I just lay out a succession of columns, with \fboxes around the appropriate ones.

\documentclass[10pt]{article}
\usepackage{tabstackengine,xcolor}
\TABstackMath
\newcommand\redbox[1]{\textcolor{red}{\fbox{\textcolor{black}{#1}}}}
\begin{document}
$\TABbinary \fboxsep=2pt \fboxrule=1pt \tabbedCenterstack{16\cdot\\11\cdot} \redbox{\tabbedCenterstack{I_1\\I_1}} \tabbedCenterstack{+11\cdot\\+16\cdot} \redbox{\tabbedCenterstack{I_2\\I_2}} \tabbedCenterstack{=\\=} \redbox{\tabbedCenterstack{13\\17}}$
\end{document}


Even though I don't use tabbed columns, I use \tabbedCenterstack in lieu of \Centerstack, so that I can employ the \TABbinary feature, which adds {} to each side of every column, which will assure proper spacing for =, +, and \cdot.

You can use the hf-tikz package:

\documentclass{article}
\usepackage{amsmath,array}
\usepackage[norndcorners,customcolors,nofill]{hf-tikz}

\hfsetbordercolor{red!70}

\begin{document}

$$\tikzset{left offset=-0.02,right offset=0.02,disable rounded corners=true} \begin{array}{@{} *{2}{ c @{} >{{}}c<{{}} @{} } c @{}} 16\cdot \tikzmarkin{A}I_1 & + & 11\cdot \tikzmarkin{B}I_2 & = & \tikzmarkin{C}13\\[1ex] 11\cdot I_1\tikzmarkend{A} & + & 16\cdot I_2\tikzmarkend{B} & = & 17\tikzmarkend{C} \end{array}$$

\end{document}


• Your answer worked. But when I had my entire document in mind, Steven B. Segletes responded to my request. – Özgür Jun 1 at 14:01