圍繞一個單元格的粗線

圍繞一個單元格的粗線

我只想在一個單元格周圍畫一條粗線。問題是下面和側面的單元格用 \cellcolor 著色,所以 \cline 不起作用。然後我找到了這個解決方案,它在電池的所有側面都產生了粗線。使用粗彩色邊框突出顯示表格單元格但我不想讓它改變單元格的高度,而且我不知道要改變什麼,所以右邊和左邊的線不會在 tabcolsep 之前停止。

在此輸入影像描述

\documentclass[11pt]{article}

\usepackage[ngerman]{babel}
\usepackage[a4paper, text={16.5cm, 25.2cm}, centering]{geometry}
\usepackage[sfdefault]{ClearSans}
\usepackage[utf8]{inputenc}
\setlength{\parskip}{1.2ex}
\setlength{\parindent}{0em}

\usepackage{tabularx}

\usepackage[dvipsnames]{xcolor}
\usepackage{colortbl}

\makeatletter
\def\highlight#1{%
\fboxrule2pt %
\hsize=\dimexpr\hsize-2\fboxrule-2\fboxsep\relax
#1%
\@endpbox\unskip\setbox0\lastbox\bgroup
\fboxrule2pt %
\fcolorbox{black}{white}{\box0}\hfill}


\begin{document}


\center{hiragana test :)}

\vspace{12pt}

\begin{center}

\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}

\setlength{\extrarowheight}{0.8cm}
\begin{tabular}{|C{1.5cm}|C{1.5cm}|C{1.5cm}|C{1.5cm}|C{1.5cm}|C{1.5cm}|}

\hline
& a & i & u & e & o \\
\hline
\cellcolor{gray!60} & & & & &  \\
\hline
k & & & & &  \\
\hline
s & & & & &  \\
\hline
t & & & & &  \\
\hline
n & & & & &  \\
\hline
h & & & & &  \\
\hline
m & & & & &  \\
\hline
y & & & & &  \\
\hline
r & & & & &  \\
\hline
w & &\cellcolor{gray!60} & \cellcolor{gray!60}& \cellcolor{gray!60}&  \\
 \hline
n & \highlight{} &\cellcolor{gray!60} &\cellcolor{gray!60} &\cellcolor{gray!60} & \cellcolor{gray!60} \\
\hline
\cellcolor{gray!60}& \cellcolor{gray!60} &\cellcolor{gray!60} &\cellcolor{gray!60} &\cellcolor{gray!60} & \cellcolor{gray!60} \\
\hline
g & & & & &  \\
\hline
z & & & & &  \\
\hline
d & & & & &  \\
\hline
b & & & & &  \\
\hline
p & & & & &  \\
\hline
\end{tabular}

\end{center}

\end{document}

答案1

需要對原始答案進行更多調整。我設法得到了一個很好的結果,如下所示:

\makeatletter
\def\highlight#1{%
\fboxrule2pt%
\hsize=\dimexpr\hsize+\fboxrule\relax
#1%
\@endpbox\unskip\setbox0\lastbox\bgroup
\fboxrule2pt%
\hspace*{-2\fboxsep}\fcolorbox{black}{white}{\box0}\hspace*{\dimexpr-2\fboxsep-\fboxrule\relax}}
\makeatother

但是,我不知道如何改變盒子的高度。


編輯:第一種使高度等於常規單元格的方法。我設法設定了fbox的高度,但是即使fbox低於cell box,cell box的高度也會稍微增加。

\makeatletter
\newsavebox\saved@arstrutbox%
\global\setbox\saved@arstrutbox\copy\@arstrutbox%
\def\highlight#1{%
\fboxrule2pt%
\ht\@arstrutbox=\dimexpr\ht\saved@arstrutbox+\extrarowheight+2\fboxrule+2\arrayrulewidth\relax%
\dp\@arstrutbox=\dimexpr\dp\saved@arstrutbox\relax%
\hsize=\dimexpr\hsize+\fboxrule\relax%
#1%
\@endpbox\unskip\setbox0\lastbox\bgroup%
\fboxrule2pt%
\hspace*{-2\fboxsep}\fcolorbox{black}{white}{\box0}\hspace*{\dimexpr-2\fboxsep-\fboxrule\relax}}
\makeatother

答案2

使用{NiceTabular}of 時nicematrix,您只需放入\Block[draw,line-width=2pt]{}{}一個單元格即可在該單元格周圍新增粗體規則。

\documentclass[11pt]{article}

\usepackage{nicematrix}

\begin{document}

\begin{center}

\setlength{\extrarowheight}{0.8cm}

\begin{NiceTabular}{*{6}{w{c}{1.5cm}}}[hvlines,color-inside]
& a & i & u & e & o \\
\cellcolor{gray!60} & & & & &  \\
k & & & & &  \\
s & & & & &  \\
r & & & & &  \\
w & &\rowcolor{gray!60} \\
n & \Block[draw,line-width=2pt]{}{} &\rowcolor{gray!60} \\
\rowcolor{gray!60} \\*
g & & & & &  \\
\end{NiceTabular}

\end{center}

\end{document}

上述程式碼的輸出

相關內容