TeX - LaTeX Asked by JT1 on May 4, 2021
Hi I am quite new to LaTeX and have attempted to put a table together as follows:
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
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]{>{raggedrightletnewlinearraybackslashhspace{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}
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:
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]{>{raggedrightletnewlinearraybackslashhspace{0pt}}p{#1}}
newcolumntype{C}[1]{>{centeringletnewlinearraybackslashhspace{0pt}}p{#1}}
arrayrulecolor{white}
setlengtharrayrulewidth{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}
Answered by Sveinung on May 4, 2021
With {NiceTabular}
of nicematrix
(with the latest version : 5.2 2020-08-19), 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}
begin{NiceTabular}{wl{5cm}||wc{1cm}|wc{1cm}|wc{1cm}||wl{1cm}||wl{1cm}||wl{1cm}}%
[ code-before = rowcolor[RGB]{101, 60, 139}{1,2} ]
& Block{1-3}{color{white}Combined cell heading}
cline{2-4}
color{white}A &color{white} B &color{white} C &color{white} D &color{white} E &color{white} F &color{white} G
end{NiceTabular}
end{document}
Answered by F. Pantigny on May 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP