I want to add a box in a tabularx table that would frame several cells vertically. There is this post that shows how to frame cells horizontally (Framing cells in a table), but I cannot figure out how to do to have the box extend over several rows. Here is what I would roughly like to get (but with a nice box):
Column 1 & Column 2 & Column 3
+-----+
bla & bla & |bla |
| |
bla & bla & |bla |
+-----+
Any idea of how I could do that?
Edit: the solutions proposed below are very nice. But they are compatible with the tabular environment only, it seems, and not with tabularx and booktabs. Below is the code I have used. Does anyone have an idea of how to extend these solutions to the tabularx style? If not, then I will just rewrite all my tables using the simple tabular style.
\documentclass{article}
\usepackage{tabularx, booktabs}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawBox}[1][]{%
\tikz[overlay,remember picture]{
\draw[black,#1]
($(left)+(-0.5em,2.0ex)$) rectangle
($(right)+(0.75em,-0.75ex)$);}
}
\begin{document}
\begin{table}[H]
\centering
\begin{tabularx}{0.3\textwidth}{Y*{4}{c}}
\toprule
& Masc & Fem & Neut\\
\midrule \cline{4-4}
Nom & hic & haec & \multicolumn{1}{|c|}{hoc} \\
Acc & hunc & hanc & \multicolumn{1}{|c|}{hoc} \\ \cline{4-4}
\bottomrule
\end{tabularx}
\end{table}
\begin{table}[H]
\centering
\begin{tabularx}{0.3\textwidth}{Y*{4}{c}}
\toprule
& Masc & Fem & Neut\\
\midrule
Nom & hic & haec & \tikzmark{left}hoc \\
Acc & hunc & hanc & hoc\tikzmark{right} \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
\cline
and the vertical parts with|
tabularx
. Show a complete MWE that is not working.\DrawBox
in your second code, so the box is not drawn. Add\DrawBox
just before\end{table}
.\DrawBox
macro (usingbooktabs
), along with some usage notes. This will work just a well withtabularx
.