# A challenge: How to reorganize the horizontal hline in the Table

I have done this table:

But I wish to have the left column with labels 1 in the Class, all join together into a single block. And similarly, I wish to have the left column with labels 2 in the Class, all join together into a single block. In short, we only need to show 1 just once, and 2 just once.

Here is my Tex code:

\begin{table}[!h]
\begin{tabular}{|c||c| c|}
\hline
Class \; & \;  math  & \; type\\ \hline
1\; & \;  spin  & \; a \\ \hline
1\; & \;  statistics & \;   b \\ \hline
1\; & \; string  & \;  c \\ \hline
2 \; & \;   spin  & \; d \\ \hline
2\;  & \;  statistics & \; e \\ \hline
2\;  & \;  string  & \; f \\ \hline
\end{tabular}
\caption{  }
\label{}
\end{table}


Thank you for all experts, if there is any comment and answer please!

-
Hi, It's easier when you provide a fully working MWE including usepackage and all that. –  Trefex Apr 29 '14 at 17:15
Add \usepackage{multirow} and use something like \multirow{3}*{1}, etc. –  jon Apr 29 '14 at 17:18

This is as good a time as any to flex your booktabs muscles:

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{c c c}
\toprule
\textbf{Class} & \textbf{Math} & \textbf{Type} \\
\midrule
1 & spin       & a \\
& statistics & b \\
& string     & c \\[.5\normalbaselineskip]
2 & spin       & d \\
& statistics & e \\
& string     & f \\
\bottomrule
\end{tabular}

\end{document}


Also consider viewing this informative graphic (source):

-
Thanks this is also brilliant, and even look nicer! +1 –  Idear Apr 29 '14 at 17:21
It seems like the \toprule, \midrule do not work for documentclass of {revtex4}, such as \documentclass[aps]{revtex4}. Do you know how to fix it, Werner? –  Idear Jun 9 '14 at 20:03

Use \cline instead of \hline (I deleted the spces \; to make the example quickly compilable):

\documentclass{article}
\usepackage{array}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|c||c| c|}
\hline
Class  &   math  &  type\\
\hline
1 &   spin  &  a \\
\cline{2-3}
&   statistics &    b \\
\cline{2-3}
&  string  &   c \\
\hline
2  &    spin  &  d \\
\cline{2-3}
&   statistics &  e \\
\cline{2-3}
&   string  &  f \\
\hline
\end{tabular}
\caption{  }
\label{}
\end{table}

\end{document}


Nor related, but try not to use a so restrictive placement specifier as [!h]; either use a less restrictive option or don't use any at all (even better).

-
Yes, thanks, I thought it is simple, but just cannot recall the \cline. +1 :-) –  Idear Apr 29 '14 at 17:18

Try this

\usepackage{multirow}
\begin{table}[!h]
\begin{tabular}{|c||c| c|}
\hline
Class \; & \;  math  & \; type\\ \hline
multirow{3}{*}{1} \; & \;  spin  & \; a \\ \hline
\; & \;  statistics & \;   b \\ \hline
\; & \; string  & \;  c \\ \hline
multirow{3}{*}{2} \; & \;   spin  & \; d \\ \hline
\;  & \;  statistics & \; e \\ \hline
\;  & \;  string  & \; f \\ \hline
\end{tabular}
\caption{  }
\label{}
\end{table}


untested because no fully working MWE.

-
Thanks this looks a option. +1 –  Idear Apr 29 '14 at 17:21