
테두리와 패딩을 추가해야 하는 매우 복잡한 테이블이 있습니다. 이제 이러한 "특수" 셀에 배경색을 지정하고 싶습니다. 하지만 색상이 패딩까지 확장되지 않습니다. 연장할 수 있는 방법이 있나요? 이것은 내 MWE 코드입니다.
\documentclass{report}
\usepackage[table]{xcolor}
\begin{document}
\begin{tabular}{cccc}
a & b & & d \\
& & & \\ \cline{1-2}
\multicolumn{1}{|@{\hspace{3em}}c@{\hspace{1em}}}{\cellcolor{red!50} E }
&
\multicolumn{1}{@{}c@{\hspace{3em}}|}{\cellcolor{red!50} F }
& & h
\\[15pt] \cline{1-2}
\end{tabular}
\end{document}
그리고 이것이 어떻게 나타나는지:
다음 이미지에서 노란색으로 강조 표시된 부분도 색상이 지정되어야 합니다. 더 나아가 상단의 테두리가 없어진 것을 발견했습니다. 왜? 어떻게 하면 그녀를 다시 되돌릴 수 있나요?
답변1
그것을 얻는 두 가지 방법이 있습니다. hhline
컬러 셀에는 메모 가 필요합니다.
\documentclass{report}
\usepackage[table]{xcolor}
\usepackage{booktabs, hhline}
\begin{document}
\begin{tabular}{cccc}
a & b & & d \\
& & & \\ \hhline{--~~}
\multicolumn{1}{| @{\color{red!50}\vrule width 3em}c@{\color{red!50}\vrule width 1em}}{\cellcolor{red!50} E }
&
\multicolumn{1}{@{}c@{\color{red!50}\vrule width 3em}|}{\cellcolor{red!50} F }
& & h
\\[15pt] \cline{1-2}
\end{tabular}
\vspace{1cm}
\begin{tabular}{cccc}
a & b & & d \\
& & & \\ \hhline{--~~}%
\multicolumn{1}{|@{\hspace{3em}}>{\columncolor{red!50}[3em][1em]}c@{\hspace{1em}}}{ E }
&
\multicolumn{1}{@{}>{\columncolor{red!50}[0.4pt][3em]}c@{\hspace{3em}}|}{ F }
& & h
\\[15pt] \cline{1-2}
\end{tabular}
\end{document}
답변2
일반적으로 나는 tikz와 \tikzmark를 사용하여 이러한 작업을 수행합니다. 수평 좌표는 일반적으로 매우 쉽게 얻을 수 있습니다. 수직에는 때때로 약간의 계산이나 더 많은 \tikzmark가 필요합니다. 깔끔한 점은 테이블 형식 전에 배경을 그릴 수 있으므로 항상 배경에 있다는 것입니다.
\documentclass{report}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\tikz[overlay,remember picture]
\fill[red!50] ([yshift=-\dimexpr\dp\strutbox+15pt]pic cs:A)
rectangle ([yshift=\ht\strutbox]pic cs:B);
\begin{tabular}{cccc}
a & b & & d \\
& & & \\ \cline{1-2}
\multicolumn{1}{|@{\tikzmark{A}\hspace{3em}}c@{\hspace{1em}}}{ E }
&
\multicolumn{1}{@{}c@{\hspace{3em}\tikzmark{B}}|}{ F }
& & h
\\[15pt] \cline{1-2}
\end{tabular}
\end{document}
답변3
환경 과 키 {NiceTabular}
대신 환경을 사용함으로써 (자체는 사용되지 않더라도 구문은 사용됩니다 ) 예상되는 출력을 직접 얻을 수 있습니다.{tabular}
colortbl-like
colortbl
colortbl
\documentclass{report}
\usepackage{xcolor}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{cccc}[colortbl-like]
a & b & & d \\
& & & \\ \cline{1-2}
\multicolumn{1}{|@{\hspace{3em}}c@{\hspace{1em}}}{\cellcolor{red!50} E }
&
\multicolumn{1}{@{}c@{\hspace{3em}}|}{\cellcolor{red!50} F }
& & h
\\[15pt] \cline{1-2}
\end{NiceTabular}
\end{document}
여러 컴파일이 필요합니다( nicematrix
내부적으로 PGF/Tikz 노드를 사용하기 때문에).