1

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

Table

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!

5
  • 3
    What have you tried? Can you post a compilable document showing what you've managed to do so far? Commented Jul 31, 2019 at 19:35
  • 1
    \multicolumnand colortbl might be interesting for you. Commented Jul 31, 2019 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. Commented Jul 31, 2019 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. Commented Jul 31, 2019 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. Commented Jul 31, 2019 at 20:09

1 Answer 1

2

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} 

enter image description here

7
  • 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. Commented Jul 31, 2019 at 20:07
  • @leandriis: Thanks for editing! Commented Jul 31, 2019 at 20:08
  • @jhon_wick: I've modified my code. Is it more like you want? Commented Jul 31, 2019 at 20:19
  • Thanks. I only need the leftmost columns as shown in the picture. Commented Jul 31, 2019 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? Commented Jul 31, 2019 at 20:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.