
Esta pregunta se basa en una pregunta anterior:Enmarcar celdas verticalmente en una tabla
Me gustaría enmarcar las celdas así y la respuesta a la pregunta anterior funciona muy bien, excepto cuando las celdas están vacías o contienen menos texto en la parte inferior del cuadro. Mira esto:
¿Algúna idea de cómo arreglar esto? (He probado diferentes especificaciones de columna; no cambia nada). ¿Cómo le digo al tikzmark que marque la posición más a la derecha en cualquier celda, ya sea vacía o llena de texto?Cualquier ayuda sería muy apreciada.
\documentclass{article}
\usepackage{tikz}
\usepackage{booktabs}
\usetikzlibrary{calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawBox}[3][]{%
\tikz[overlay,remember picture]{
\draw[black,#1]
($(#2)+(-0.5em,2.0ex)$) rectangle
($(#3)+(0.75em,-0.75ex)$);}
}
\begin{document}
\begin{tabular}{*{7}{c}}\toprule
Col 1 & Col 2 & Col 3 & Col 4 & Col 5 & Col 6 & Col 7 \\ \cmidrule(lr){2-6}
0 & 1 & \tikzmark{top left 1}abcd more text & 0 & 0 & 0 & 1 \\
1 & 0 & www & 0 & 0 & 0 & 1 \\
0 & 1 & \tikzmark{bottom right 1} & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 \\
\bottomrule
\end{tabular}
\DrawBox[ultra thick, red]{top left 1}{bottom right 1}
\end{document}
Respuesta1
Llene la celda vacía:
\documentclass{article}
\usepackage{tikz}
\usepackage{booktabs}
\usetikzlibrary{calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawBox}[3][]{%
\tikz[overlay,remember picture]{
\draw[black,#1]
($(#2)+(-0.5em,2.0ex)$) rectangle
($(#3)+(0.75em,-0.75ex)$);}
}
\begin{document}
\begin{tabular}{*{7}{c}}\toprule
Col 1 & Col 2 & Col 3 & Col 4 & Col 5 & Col 6 & Col 7 \\ \cmidrule(lr){2-6}
0 & 1 & \tikzmark{top left 1}abcd more text & 0 & 0 & 0 & 1 \\
1 & 0 & www & 0 & 0 & 0 & 1 \\
0 & 1 & \hspace*{\fill}\tikzmark{bottom right 1} & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 \\
\bottomrule
\end{tabular}
\DrawBox[ultra thick, red]{top left 1}{bottom right 1}
\end{document}
Respuesta2
Con {NiceTabular}
de nicematrix
.
\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}
\usepackage{booktabs}
\begin{document}
\begin{NiceTabular}{*{7}{c}}
\toprule
Col 1 & Col 2 & Col 3 & Col 4 & Col 5 & Col 6 & Col 7 \\
\cmidrule(lr){2-6}
0 & 1 & \Block[tikz={offset=3pt,draw=red}]{3-1}{} abcd more text & 0 & 0 & 0 & 1 \\
1 & 0 & www & 0 & 0 & 0 & 1 \\
0 & 1 & & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 \\
\bottomrule
\end{NiceTabular}
\end{document}