![tabularx 中具有选定宽度的虚线垂直彩色线](https://linux22.com/image/425360/tabularx%20%E4%B8%AD%E5%85%B7%E6%9C%89%E9%80%89%E5%AE%9A%E5%AE%BD%E5%BA%A6%E7%9A%84%E8%99%9A%E7%BA%BF%E5%9E%82%E7%9B%B4%E5%BD%A9%E8%89%B2%E7%BA%BF.png)
在下面的代码中,我能够生成一定宽度的灰色虚线垂直线。我想用虚线替换实线。我尝试:
使用该arydshln
包添加,但会导致错误。
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{lscape}
\usepackage{geometry}
\usepackage{colortbl}
\usepackage{tcolorbox}
\geometry{left=2mm,right=2mm}
\geometry{top=3mm,bottom=3mm}
\newcolumntype{?}{!{\color{gray}\vrule width 0.5pt}}
\begin{document}
\begin{table}
\caption{Caption}
\begin{tabularx}{0.4\textwidth}{>{\hsize=\hsize}X?>{\hsize=\hsize}X}
\hline\\[0.2pt]
A & B\\
D & E\\
\end{tabularx}
\label{table1}
\end{table}
\end{document}
答案1
\documentclass{article}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage{arydshln}
\begin{document}
\begin{table}
\caption{Caption}
\arrayrulecolor{gray}
\begin{tabularx}{0.4\textwidth}{X:X}
\arrayrulecolor{black}
\hline\\[0.2pt]
A & B\\
D & E\\
\end{tabularx}
\label{table1}
\end{table}
\end{document}
答案2
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\tikzset
{
dashed 1/.style =
{
red ,
dash pattern = on 2pt off 3pt ,
line width = 1 pt
} ,
dashed 2/.style =
{
blue ,
dash pattern = on 1pt off 1pt ,
line width = 2pt
}
}
\begin{NiceTabular}{wc{2cm}wc{2cm}}
\hline
A & B\\
D & E\\
\CodeAfter
\begin{tikzpicture}
\draw [dashed 1] (row-1-|col-2) -- (row-3-|col-2) ;
\draw [dashed 2] (row-1-|col-3) -- (row-3-|col-3) ;
\draw [dashed 1] (row-2-|col-1) -- (row-2-|col-3) ;
\draw [dashed 2] (row-3-|col-1) -- (row-3-|col-3) ;
\end{tikzpicture}
\end{NiceTabular}
\end{document}