I am trying to add a table like below in Latex. Can anyone please help?


Here is the one I have:


\begin{tabular}{ |p{1cm}|p{1cm} |p{1cm}|p{1cm}|  }
\multicolumn{2}{|c|}{t = 5} \\
Selection & EC  & Selection & EC  \\
AF & AF & Selection & EC  \\
Ala    & ALA & Selection & EC  \\

However, this alters row color instead of column and also I am unable to add other columns.


I am trying below code as posted by Bernerd:

\begin{tabular}{ || *{2}{>{\columncolor{blue!30!white!50}}p{1.5cm}| >{\columncolor{white}}p{1.5cm}|| }}
\rowcolor{white} \multicolumn{2}{||c|}{t = 5} & \multicolumn{2}{||c||}{t = 10}  \\
Selection & EC & Selection & EC \\
Afghan & AF & Afghan & AF\\
Aland  & ALA & Aland  & ALA \\

However, the column separating lines are not aligned!

  • 3
    What have you tried? Can you post a compilable document showing what you've managed to do so far? – Alan Munn Jul 31 '19 at 19:35
  • 1
    \multicolumnand colortbl might be interesting for you. – leandriis Jul 31 '19 at 19:36
  • 2
    You might want to use \columncolor instead or \rowcolor. To add more columns, add as many column specifiers as neede (for example lll for three left aligned columns or |p{3cm}|p{3cm}|p{3cm}| for three columns that are 3 cm wide and are separated by vertical lines. – leandriis Jul 31 '19 at 19:48
  • Please also reconsider if using \setlength{\arrayrulewidth}{1mm}\setlength{\tabcolsep}{18pt}\renewcommand{\arraystretch}{2.5} is really a good idea as this will give you extremely wide lines and also quite a lot of empty space aroudn the contents of each cell. If your table will contain 11 columns, you will most likely not fit it onto a page with these settings. – leandriis Jul 31 '19 at 20:04
  • I have removed those lines and tried to use \columncolor. It gives me an error in overleaf. Also, I am still unable to add extra columns. – jhon_wick Jul 31 '19 at 20:09

Is this what you want?

\usepackage[table, svgnames]{xcolor}
\usepackage{hhline, booktabs}

\begin{tabular}{ |l |*{2}{>{\columncolor{green!80!yellow!50}}p{2.2cm} >{\columncolor{green!50!yellow!40}}p{2.3cm}| }}
\rowcolor{white} & \multicolumn{2}{c|}{\bfseries t = 5} & & \\
Packet & Selection & EC & Selection & EC \\
Switching & Afghanistan & AF & Afghanistan & AF\\
\arrayrulecolor{Aquamarine}\midrule[1.2pt] \arrayrulecolor{black}
Energy & Aland Islands & ALA &Aland Islands & ALA \\


enter image description here

  • Thank you. The problem is I can't add more column like the fig in my questions. Also, I don't know how to add the leftmost column without any heading. – jhon_wick Jul 31 '19 at 20:07
  • @leandriis: Thanks for editing! – Bernard Jul 31 '19 at 20:08
  • @jhon_wick: I've modified my code. Is it more like you want? – Bernard Jul 31 '19 at 20:19
  • Thanks. I only need the leftmost columns as shown in the picture. – jhon_wick Jul 31 '19 at 20:24
  • I'm not sure I understand the exact layou you want: the leftmost column should not be coloured, with an empty head, then the other columns should follow a pattern of two colours, with the first row non-coloured, and vertical lines only at both ends of the pattern, but not between the columns inside the pattern? – Bernard Jul 31 '19 at 20:33

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.