Enquadrando células VAZIAS em uma tabela

Enquadrando células VAZIAS em uma tabela

Esta pergunta é baseada em uma pergunta anterior:Enquadrar células verticalmente em uma tabela

Gostaria de enquadrar as células assim e a resposta à pergunta anterior funciona perfeitamente - exceto quando as células estão vazias ou contêm menos texto na parte inferior da caixa. Veja isso: insira a descrição da imagem aqui

Alguma ideia de como consertar isso? (Tentei diferentes especificações de coluna – não muda nada.) Como posso dizer ao tikzmark para marcar a posição mais à direita em qualquer célula, seja ela vazia ou preenchida com texto?Qualquer ajuda seria muito 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}

Responder1

Preencha a célula vazia:

\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}

insira a descrição da imagem aqui

Responder2

Com {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}

Saída do código acima

informação relacionada