1

How can I create a table like the following? enter image description here

\documentclass{article}

\usepackage{svg}
\usepackage{amsmath}
\usepackage{float}
\usepackage{comment} 
\usepackage{subfig} 
\usepackage{url} 
\usepackage{physics} 
\usepackage{hyperref} 
\usepackage{booktabs} 
\usepackage[super]{nth} 
\usepackage{amssymb} 
\usepackage[bottom]{footmisc} 
\usepackage{multirow} 
\usepackage{color,colortbl}

\begin{document}

\begin {table}[H]
\caption {Table Title} \label{tab:title}
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\multirow{2}{*}{A} & \multicolumn{3}{c|}{B} \\
\cline{2-4}
 & C & D &F\\
\hline
1 & x &  x & x \\
\hline
 2 & x &x & x\\
\hline
3 & x & x& x\\
\hline
% etc. ...
\end{tabular}
\end{center}
\end{table}

\end{document}
5
  • 1
    have you tried to create a basic table with the same content? At least this would be a starting point to attract further advice. At the moment it comes across as you wanting someone else to do the hard work for you :-( May 9, 2016 at 12:03
  • Could you please show us what you have already tried in LaTeX in the from of a minimal working example (MWE)?
    – ienissei
    May 9, 2016 at 12:06
  • This one I made by Microsoft Word. But I have a similar table in latex without the coloring. I used "\usepackage[table]{xcolor}" and I got errors. I wanted to see if there is another approach than using \multicolumn and \multirow that is compatible with the coloring of certain cells.
    – faf
    May 9, 2016 at 12:15
  • @PeterEbelsberger A Minimal Working Example is added 20 min ago!
    – faf
    May 9, 2016 at 12:46
  • @faf a MWE must be compilable --- starting from \documentclass and adding all the needed packages. Yours is just a snippet...
    – Rmano
    May 9, 2016 at 13:25

2 Answers 2

1

Similar solution, other package:

\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin {table}[h]
\caption {Table Title} \label{tab:title}
\begin{center}
\begin{tabular}{c c c c c}
\rowcolor{Gray}
\multicolumn{1}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{1}{c}{C} & \multicolumn{1}{c}{D} \\
\hline
\addlinespace
\rowcolor{Gray}
& E & F & &\\
1 & x &  x & x \\
 2 & x &x & x\\
3 & x & x& x\\
\hline
% etc. ...
\end{tabular}
\end{center}
\end{table}

produces the following table.

enter image description here

1
  • @faf good that the above solution was useful. It will help others with similar issues if you mark the answer as accepted (by clicking on the tick) ;-) May 10, 2016 at 7:48
0

I edited your code a bit and now it looks like this:

enter image description here

Here is the code:

\begin {table}[H]
\caption {Table Title} \label{tab:title}
\centering
\begin{tabular}{|c|c|c|c|c|}
\toprule
\rowcolor{Gray} & \multicolumn{2}{c|}{B}  &  &\\
\cline{2-3}
\rowcolor{Gray}\multirow{-2}{*}{A}&E&F&\multirow{-2}{*}{C}&\multirow{-2}{*}{D}\\
\midrule
1 & x &  x & x &x\\
\midrule
 2 & x &x & x&x\\
\midrule
3 & x & x& x&x\\
\bottomrule
% etc. ...
\end{tabular}
\end{table}

I also replaced your \hline by \top-/mid-/bottomrule as it makes nicer tables. I also replaced \begin{center}...\end{center} through \centering.

Unfortunately, your \cline won't be visible as the color hides the line. The reason for this you can also see here in a former asked question.

7
  • Thanks! Which package should I use with it?
    – faf
    May 9, 2016 at 13:03
  • You need these packages: \usepackage{multirow} \usepackage{booktabs} \usepackage[table, dvipsnames]{xcolor}
    – SeRe
    May 9, 2016 at 13:09
  • I'm getting again this error. "option clash for package xcolor." P.S. I'm using Overleaf, but it shouldn't matter I guess.
    – faf
    May 9, 2016 at 13:11
  • Okay, then you are using a package, which already loads xcolor. Do you use tikz?
    – SeRe
    May 9, 2016 at 13:17
  • you get option clashes with \usepackage[table]{xcolor} with other packages, for example \usepackage{textgreek}. What does the editor in Overleaf flag up? May 9, 2016 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .