![在表格内创建框架](https://linux22.com/image/371277/%E5%9C%A8%E8%A1%A8%E6%A0%BC%E5%86%85%E5%88%9B%E5%BB%BA%E6%A1%86%E6%9E%B6.png)
我想在我的表格中放置一个框架/框,例如,我有一张表格 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}
渲染结果如下
现在,我想要的是类似以下内容
这可能吗?如果可以,我该怎么做?
答案1
使用tikzmark
:P
\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}
答案2
由于已知框列的宽度(每个 2em),因此可以计算出框尺寸:
\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}