
이 질문은 이전 질문을 기반으로 합니다.표에서 셀의 세로 방향 지정
저는 셀의 프레임을 그와 같이 만들고 싶습니다. 이전 질문에 대한 답변은 훌륭하게 작동합니다. 단, 셀이 비어 있거나 상자 하단에 더 적은 텍스트가 포함되어 있는 경우는 예외입니다. 이것 좀 봐:
이 문제를 해결하는 방법을 아시나요? (다른 열 사양을 시도했지만 아무것도 변경되지 않습니다.) 비어 있거나 텍스트로 채워져 있는지 여부에 관계없이 모든 셀에서 가장 오른쪽 위치를 표시하도록 tikzmark에 어떻게 지시합니까?어떤 도움이라도 주시면 감사하겠습니다.
\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}
답변1
빈 셀을 채웁니다.
\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}
답변2
의 .{NiceTabular}
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}