5

Hi I am quite new to LaTeX and have attempted to put a table together as follows:

enter image description here

It is pretty close to what I want but I can't seem to find a way to separate the last three columns with white space. I've used hhline to draw the purple line so that it fills in the horizontal gap but I do not want it to show up in white spaces between each column. This is what I want as the end result

enter image description here

Any help would be greatly appreciated and am happy for any suggestions on how to approach this.

Cheers.

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}

2 Answers 2

3

This was a very challenging one. I have simplified your code, removed seemingly unnecessary \multirow and \multicolumn. The reason for you problem was the ?-column, because hhline did not recognise it as a column, so it was not possible to ‘cross’ it the correct way.

Here is the result and the code:

enter image description here

\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

With {NiceTabular} of nicematrix, you have directly the expected result (because \cline is respected by the coloring tools provided by {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}

Output of the first code

In that code, I have fixed by hand (with wc{1cm}) the width of the three columns under Combined cell heading. If you prefer, it's also possible to create only one column for that Combined cell heading and split in three the content of the corresponding cell in the second row.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{xcolor}

\begin{document}

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

\end{document}

Output of the second code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .