我有这张表,基于这:
\documentclass{book}
\usepackage{colortbl}
\usepackage{hhline}
\begin{document}
\setlength{\arrayrulewidth}{2pt}
\begin{tabular}{|c|c|c|}
\hline
& & \\ \hline
& & \\
\hhline{
>{\arrayrulecolor{yellow}} |
>{\arrayrulecolor{black}} -
>{\arrayrulecolor{yellow}} |
>{\arrayrulecolor{black}} -
>{\arrayrulecolor{yellow}} |
>{\arrayrulecolor{black}} -
>{\arrayrulecolor{yellow}} |
>{\arrayrulecolor{black}}
}
& & \\
\hhline{
>{\arrayrulecolor{yellow}} |
>{\arrayrulecolor{black}} -
>{\arrayrulecolor{yellow}} |
>{\arrayrulecolor{black}} -
>{\arrayrulecolor{yellow}} |
>{\arrayrulecolor{black}} -
>{\arrayrulecolor{yellow}} |
>{\arrayrulecolor{black}}
}
& & \\ \hline
\end{tabular}
\end{document}
我希望第三行的垂直线是黄色。
我读过了这,但颜色会影响所有行。
答案1
基于@Zarko 评论的示例解决方案:
\documentclass{book}
\usepackage{colortbl}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
vlines = {1,3,5}{red},
vlines = {2,4}{blue},
}
Alpha & Beta & Gamma & Delta \\
Epsilon & Zeta & Eta & Theta \\
Iota & Kappa & Lambda & Mu \\
Nu & Xi & Omicron & Pi \\
Rho & Sigma & Tau & Upsilon \\
\end{tblr}
\end{document}
答案2
像这样?
正如我在评论中提到的,这可以通过使用tabularray
包相对简单地完成(我使用版本 2022C):
\documentclass[margin=3mm]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{colspec = {*{3}{Q[c]}},
hline{2-Y} = {even}{black},
hline{2-Y} = {odd}{yellow,leftpos = 0, rightpos = 0},
hline{1,Z} = {black},
vlines,
}
& & \\
& & \\
& & \\
\end{tblr}
\end{document}
或这个:
\documentclass[margin=3mm]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{colspec = {*{3}{Q[c]}},
hline{2-Y} = {even}{black},
hline{2-Y} = {odd}{yellow,leftpos = 0, rightpos = 0},
hline{1,Z} = {black},
vline{1,2,4} = {black}, vline{3} = {yellow},
}
& & \\
& & \\
& & \\
\end{tblr}
\end{document}
答案3
{NiceTabular}
包的nicematrix
行为与经典环境 {tabular} (of array
) 的行为相同,但还会在单元格、列和行下创建 PGF/Tikz 节点。您可以使用 Tikz 绘制任何您想要的规则和任何 Tikz 线条样式。
\documentclass{book}
\usepackage{nicematrix,tikz}
\begin{document}
\begin{NiceTabular}{cccc}[hvlines]
& & & \\
& & & \\
\CodeAfter
\begin{tikzpicture} [line width = 1pt]
\draw [red] (1-|1) -- (1-|2) (1-|3) -- (1-|4) ;
\draw [white] (2-|2) -- (2-|5) ;
\draw [densely dash dot] (2-|2) -- (2-|5) ;
\draw [blue,double] (1-|2) -- (3-|2) ;
\end{tikzpicture}
\end{NiceTabular}
\end{document}