4

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

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.