在表格中的垂直线上绘制的 hhline

在表格中的垂直线上绘制的 hhline

你好,我对 LaTeX 还很陌生,并尝试整理如下表格:

在此处输入图片描述

它非常接近我想要的,但我似乎找不到用空白分隔最后三列的方法。我使用 hhline 绘制了紫色线条,以便它填充水平间隙,但我不希望它出现在每列之间的空白处。这是我想要的最终结果

在此处输入图片描述

任何帮助都将不胜感激,并且我很高兴听到任何关于如何解决这一问题的建议。

干杯。

JT

\documentclass[a4paper]{article}
\usepackage{colortbl,multirow,hhline, xcolor}
\usepackage[margin=2cm]{geometry}

\begin{document}

% Define colours and columns
\definecolor{Purple}{RGB}{101, 60, 139}
\newcolumntype{?}{!{\color{white}\vrule width 1.5mm}}
\newcolumntype{P}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\arrayrulecolor{white}


% Document
\begin{tabular}{P{5cm}c|c|cccc}
    \hline
    % R1C1
    \cellcolor{Purple} & 
    % R1C2-4
    \multicolumn{3}{?c?}{\cellcolor{Purple}\textcolor{white}{Combined cell heading}} &  
    % R1C5
    \multicolumn{1}{c?}{\cellcolor{Purple}} & 
    % R1C6 
    \multicolumn{1}{c?}{\cellcolor{Purple}} & 
    % R1C7
    \multicolumn{1}{c}{\cellcolor{Purple}}\\
    % Drawing line to split first row
    \hhline{>{\arrayrulecolor{Purple}}->{\arrayrulecolor{white}}--->{\arrayrulecolor{Purple}}--->{\arrayrulecolor{white}}}
    % R2C1
    \multirow{1}{*}{\cellcolor{Purple}\textcolor{white}{A}} & 
    % R2C2
    \multicolumn{1}{?c!{\color{white}\vrule width 1pt}}{\cellcolor{Purple}\textcolor{white}{B}}  & 
    % R2C3
    \multicolumn{1}{|c!{\color{white}\vrule width 1pt}}{\cellcolor{Purple}\textcolor{white}{C}}  & 
    % R2C4
    \multicolumn{1}{|c?}{\cellcolor{Purple}\textcolor{white}{D}}  & 
    % R2C5
    \multicolumn{1}{P{1cm}?}{\cellcolor{Purple}\textcolor{white}{E}} & 
    % R2C6
    \multicolumn{1}{P{1cm}?}{\cellcolor{Purple}\textcolor{white}{F}} &
    % R2C7
    \multicolumn{1}{P{1cm}}{\cellcolor{Purple}\textcolor{white}{G}}\\
\end{tabular}
\end{document}

答案1

这是一个非常有挑战性的问题。我简化了你的代码,删除了看似不必要的\multirow\multicolumn。你问题的原因是?-column上,因为线没有将其识别为一根柱子,因此无法以正确的方式“穿过”它。

以下是结果和代码:

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{multirow,hhline}
\usepackage[table]{xcolor}
\usepackage[margin=2cm]{geometry}

\renewcommand{\arraystretch}{1.2}
\setlength{\extrarowheight}{1pt}

\begin{document}

% Define colours and columns
\definecolor{Purple}{RGB}{101, 60, 139}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

\arrayrulecolor{white}
\setlength\arrayrulewidth{0.5mm}


\begin{tabular}{L{5cm}||c|c|c||C{1cm}||C{1cm}||C{1cm}}
    \hline
    % R1C1
    \cellcolor{Purple} & 
    % R1C2-4
    \multicolumn{3}{c||}{\cellcolor{Purple}\textcolor{white}{Combined cell heading}} &  
    % R1C5
    \cellcolor{Purple} & 
    % R1C6 
    \cellcolor{Purple} & 
    % R1C7
    \cellcolor{Purple}\\
    % Drawing line to split first row
    \hhline{>{\arrayrulecolor{Purple}}->{\arrayrulecolor{white}}||---||>{\arrayrulecolor{Purple}}->{\arrayrulecolor{white}}||>{\arrayrulecolor{Purple}}->{\arrayrulecolor{white}}||>{\arrayrulecolor{Purple}}-}
    % R2C1
    \cellcolor{Purple}\textcolor{white}{A} & 
    % R2C2
    \cellcolor{Purple}\textcolor{white}{B} & 
    % R2C3
    \cellcolor{Purple}\textcolor{white}{C} & 
    % R2C4
    \cellcolor{Purple}\textcolor{white}{D} & 
    % R2C5
    \cellcolor{Purple}\textcolor{white}{E} & 
    % R2C6
    \cellcolor{Purple}\textcolor{white}{F} &
    % R2C7
    \cellcolor{Purple}\textcolor{white}{G}\\
\end{tabular}


\end{document}

答案2

使用,您{NiceTabular}可以nicematrix直接获得预期的结果(因为\cline提供的着色工具尊重{NiceTabular})。

\documentclass{article}

\usepackage{nicematrix}
\usepackage{xcolor}

\begin{document}

\arrayrulecolor{white}
\doublerulesepcolor{white}
\color{white}
\begin{NiceTabular}{wl{5cm}||wc{1cm}|wc{1cm}|wc{1cm}||wl{1cm}||wl{1cm}||wl{1cm}}%
\CodeBefore
  \arraycolor[RGB]{101, 60, 139}
\Body
  & \Block{1-3}{Combined cell heading} \\
  \cline{2-4}
  A & B & C & D & E & F & G 
\end{NiceTabular}

\end{document}

相关内容