Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have done this table:

enter image description here

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!

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

3 Answers 3

up vote 6 down vote accepted

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

enter image description here

\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):

enter image description here

share|improve this answer
2  
Thanks this is also brilliant, and even look nicer! +1 –  Idear Apr 29 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 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}

enter image description here

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).

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

For your problem,

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.

share|improve this answer
1  
Thanks this looks a option. +1 –  Idear Apr 29 at 17:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.