1

I would like to put a frame/box around certain elements within a table of mine, for example, I have a table ala

\begin{tabular}{ |c|l| *{3}{>{\centering\arraybackslash}p{2em}} |c|c|c| }
    \hline
    Problem $I_k$ & Solved $C_k$ & \multicolumn{3}{ c |}{Solution to $C_k$} & Current & Pursue & Stored\\
    \cline{3-5}
    & & $x_1$ & $x_2$ & $z$ & & & \\ \hline
    $I_0$ & $C_0$ & $\frac{44}{9}$ & $\frac{86}{9}$ & $\frac{188}{3}$ & - & $I_0$ & - \\ \hline
    $I_1$ & $C_1$ & $4$ & $10$ & $60$ & 60 & $I_0$ & - \\
    $I_2$ & $C_2$ & $5$ & $\frac{47}{5}$ & $\frac{313}{5}$ & & & \\ \hline
\end{tabular}

which renders like this

enter image description here

Now, what I would like is something like the following

enter image description here

is this possible? And if so, how would I go about that?

1

Using tikzmark :P

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}

\begin{document}
\setlength{\extrarowheight}{1ex}
\begin{tabular}{ |c|l| *{3}{>{\centering\arraybackslash}p{2em}} |c|c|c| }
    \hline
    Problem $I_k$ & Solved $C_k$ & \multicolumn{3}{ c |}{Solution to $C_k$} & Current & Pursue & Stored\\
    \cline{3-5}
    & & $x_1$ & $x_2$ & $z$ & & & \\ \hline
    $I_0$ & $C_0$ & $\frac{44}{9}$ & $\frac{86}{9}$ & $\frac{188}{3}$ & - & $I_0$ & - \\ \hline
    $I_1$ & $C_1$ & \tikzmark{a}$4$ & $10$ & $60$\tikzmark{b} & 60 & $I_0$ & - \\
    $I_2$ & $C_2$ & $5$ & $\frac{47}{5}$ & $\frac{313}{5}$ & & & \\ \hline
\end{tabular}
\begin{tikzpicture}[remember picture,overlay]
  \draw ($(pic cs:a)+(-\fboxsep,-\fboxsep)$) rectangle ($(pic cs:b)+(\fboxsep,1em)$);
\end{tikzpicture}
\end{document}
0

Since the width of boxed columns is known (2em each), the box dimensions can be calculated:

\documentclass{article}
\usepackage{array}
\begin{document}
\renewcommand*{\arraystretch}{1.5}
\begin{tabular}{ |c|l| *{3}{>{\centering\arraybackslash}p{2em}} |c|c|c| }
    \hline
    Problem $I_k$ & Solved $C_k$ & \multicolumn{3}{ c |}{Solution to $C_k$} & Current & Pursue & Stored\\
    \cline{3-5}
    & & $x_1$ & $x_2$ & $z$ & & & \\ \hline
    $I_0$ & $C_0$ & $\frac{44}{9}$ & $\frac{86}{9}$ & $\frac{188}{3}$ & - & $I_0$ & - \\ \hline
    $I_1$ & $C_1$ &
      \multicolumn{3}{l|}{%
        \setlength{\fboxrule}{.8pt}%
        \sbox0{$4$}%
        \kern\dimexpr 1em-\fboxrule-\fboxsep-.5\wd0\relax
        \fbox{%
          \copy0\relax
          \kern\dimexpr -.5\wd0 + 1em + 2\tabcolsep\relax
          \hbox to 2em{\hfill$10$\hfill}%
          \sbox0{$60$}%
          \kern\dimexpr 2\tabcolsep + 1em - .5\wd0\relax
          \box0\relax
        }%
      }%
      & 60 & $I_0$ & - \\
    $I_2$ & $C_2$ & $5$ & $\frac{47}{5}$ & $\frac{313}{5}$ & & & \\ \hline
\end{tabular}
\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.