# Latex table formatting

Here is the one I have:

    \documentclass{article}
\usepackage[table]{xcolor}
\begin{document}
\renewcommand{\arraystretch}{1.3}

{\columncolor{2}{green!80!yellow!50}{green!70!yellow!40}
\begin{tabular}{ |p{1cm}|p{1cm} |p{1cm}|p{1cm}|  }
\hline
\multicolumn{2}{|c|}{t = 5} \\
\hline
Selection & EC  & Selection & EC  \\
\hline
AF & AF & Selection & EC  \\
Ala    & ALA & Selection & EC  \\
\hline
\end{tabular}
}
\end{document}


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

UPDATE:

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}|| }}
\hline
\rowcolor{white} \multicolumn{2}{||c|}{t = 5} & \multicolumn{2}{||c||}{t = 10}  \\
\hline
\hline
Selection & EC & Selection & EC \\
\hline
Afghan & AF & Afghan & AF\\
Aland  & ALA & Aland  & ALA \\
\hline
\end{tabular}


However, the column separating lines are not aligned!

• 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
• \multicolumnand colortbl might be interesting for you. – leandriis Jul 31 '19 at 19:36
• 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?

\documentclass{article}%
\usepackage{geometry}
\usepackage[table, svgnames]{xcolor}
\usepackage{hhline, booktabs}
\begin{document}

{\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{12pt}
\renewcommand{\arraystretch}{2.5}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\sffamily
\begin{tabular}{ |l |*{2}{>{\columncolor{green!80!yellow!50}}p{2.2cm} >{\columncolor{green!50!yellow!40}}p{2.3cm}| }}
\hline
\rowcolor{white} & \multicolumn{2}{c|}{\bfseries t = 5} & & \\
\hhline{|~|>{\arrayrulecolor{Aquamarine}}-->{\arrayrulecolor{black}}|>{\arrayrulecolor{Aquamarine}}-->{\arrayrulecolor{black}}|}
Packet & Selection & EC & Selection & EC \\
\hhline{|~|>{\arrayrulecolor{Aquamarine}}-->{\arrayrulecolor{black}}|>{\arrayrulecolor{Aquamarine}}-->{\arrayrulecolor{black}}|}
Switching & Afghanistan & AF & Afghanistan & AF\\
\arrayrulecolor{Aquamarine}\midrule[1.2pt] \arrayrulecolor{black}
Energy & Aland Islands & ALA &Aland Islands & ALA \\
\hline
\end{tabular}
}

\end{document}


• 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