0

I try to use \multirow to create the table below, but it failed. Making the "unit" below the item causes table creation difficult for me. Anyone can help me out? enter image description here

1
  • 7
    Why don't you give us at least the data and the code you have produced so far?
    – vaettchen
    Commented Aug 24, 2014 at 6:25

4 Answers 4

8

I don't think that using \multirow improves the look of the header cells -- quite the opposite, actually. The big gap between the first and second group of three columns seems excessive; you may get a better overall effect by trimming the \cmidrules to leave a modest visual gap. Finally, since the data are numeric, you may want to consider using the S column type (provided by the siunitx package) instead of the basic c column type.

enter image description here

\documentclass{book}
\usepackage{booktabs,caption,siunitx}
\begin{document}
\begin{table}
  \centering
  \caption{Comparison of Groups A and B}\label{AB}
  \begin{tabular}{@{}l*{7}{S[table-format=1.3]}@{}}
  \toprule
  No. & A & \multicolumn{3}{c}{Group A} &\multicolumn{3}{c@{}}{Group B}\\
  \cmidrule(lr){3-5}
  \cmidrule(l){6-8}
  &&A&B&C&A&B&C\\
  &{(unit)}&{(unit)}&&{(unit)}&{(unit)}&&{(unit)}\\
  \midrule
  1 & 0.751 & 0.498 & 0.706 & 0.823 & 0.439 & 0.490 & 0.276\\
  2 & 0.255 & 0.960 & 0.032 & 0.695 & 0.382 & 0.446 & 0.680\\
  3 & 0.506 & 0.340 & 0.277 & 0.317 & 0.766 & 0.646 & 0.655\\
  4 & 0.699 & 0.585 & 0.046 & 0.950 & 0.795 & 0.709 & 0.163\\
  5 & 0.891 & 0.224 & 0.097 & 0.034 & 0.187 & 0.755 & 0.119\\
  \bottomrule
  \end{tabular}
\end{table}
\end{document} 
2

Table Construction:

Code:

\documentclass[table]{book}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{caption}
\usepackage{listings}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular*}{0.90\textwidth}{@{\extracolsep{\fill}}rrrrrrrr}
\hline \hline
\multirow{4}{*}{No} & \multirow{4}{*}{A} & \multicolumn{3}{c}{Group A} & \multicolumn{3}{c}{Group B}\\
                                 & \multirow{4}{*}{(unit)}&\multicolumn{3}{c}{-------------------------------}  &\multicolumn{3}{c}{-------------------------------} \\
                               &     & A & \quad \quad     B & C & A &\quad \quad B &C \\
                               &     &  (unit) & &(unit)  &  (unit) & &(unit)\\
\hline

1 & 0.751 & 0.498 & 0.706 & 0.823 & 0.439 & 0.490 & 0.276 \\
2 & 0.255 & 0.960 & 0.032 & 0.695 & 0.382 & 0.446 & 0.680 \\
3&  0.506 & 0.340 & 0.277 & 0.317 & 0.766 & 0.646 & 0.655 \\
4&  0.699 & 0.585 & 0.046 & 0.950 & 0.795 & 0.709 &0.163 \\
5 & 0.891 & 0.224 & 0.097 & 0.034 & 0.187 & 0.755 & 0.119\\
\hline \hline

\end{tabular*}
\caption{Comparison of Group A and B}
\label{tab:compr}
\end{table}

\end{document}

Result

enter image description here

2
  • Thanks for your help. It seams that I get a better solution. See below
    – user22986
    Commented Aug 24, 2014 at 7:35
  • 1
    If you're going to use ------... to create long lines, be sure to use a number of dashes that's an exact multiple of three. Otherwise you end up with a bunch of em-dashes followed by either a simple dash (as in the screenshot) or an en-dash. That said, either \cline or \cmidrule would seem to provide a more natural way for obtaining the lines in question.
    – Mico
    Commented Aug 24, 2014 at 9:11
2
\documentclass[table]{book}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{caption}
\begin{document}
\begin{table}[H]
  \centering
  \caption{Comparison of Group A and B}\label{AB}
  \begin{tabular}{ccccccccc}
  \toprule
  \multirow{3}[4]{*}{No.} & & \multicolumn{3}{c}{Group A} & &\multicolumn{3}{c}{Group B}\\
  \cmidrule(r){3-5}
  \cmidrule(r){7-9}
  &A&A&\multirow{2}[4]{*}{B}&C&&A&\multirow{2}[4]{*}{B}&C\\
  &(unit)&(unit)&&(unit)&&(unit)&&(unit)\\
  \midrule
  1 & 0.751 & 0.498 & 0.706 & 0.823 && 0.439 & 0.490 & 0.276 \\
  2 & 0.255 & 0.960 & 0.032 & 0.695 && 0.382 & 0.446 & 0.680 \\
  3 &  0.506 & 0.340 & 0.277 & 0.317 && 0.766 & 0.646 & 0.655 \\
  4 &  0.699 & 0.585 & 0.046 & 0.950 && 0.795 & 0.709 &0.163 \\
  5 & 0.891 & 0.224 & 0.097 & 0.034 && 0.187 & 0.755 & 0.119\\
  \bottomrule
  \end{tabular}
\end{table}
\end{document} 

enter image description here

4
  • 1
    please use the '{}' button to format your code as code. also I would consider keeping all the column names on the same row, simply leaving blanks on the unit row where none is necessary - and i have seen that done with additional single-column cmidrules between unit and column name..
    – greyshade
    Commented Aug 24, 2014 at 7:38
  • 1
    The placement of the B column headers strikes me as bordering on the hideous. Loading the multicol and caption packages isn't needed for this MWE, is it? What is the purpose of the table option in the \documentclass command? The [H] location specifier doesn't do anything unless the float package is loaded as well.
    – Mico
    Commented Aug 24, 2014 at 7:44
  • @Mico: Thanks for the pointing out the problems.
    – user22986
    Commented Aug 24, 2014 at 16:49
  • @greyshade: Thanks for your suggestion. I will keep all the column names on the same row. Good suggestion!
    – user22986
    Commented Aug 24, 2014 at 16:50
2

A different alignment for the first rows, an automatic numbering of rows and a slight simplification of code with the makecell or stackengine packages (no multirows):

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{booktabs, caption, siunitx}
\usepackage{makecell}
\renewcommand\theadalign{tc}

\usepackage{tabstackengine}
\setstackEOL{\\}
\newcounter{rowno}
\newcommand\emptycell{\multicolumn{1}{c}{}}
\providecommand*\No{N\textsuperscript{\kern0.06em\underline{\kern-0.06em o\kern-0.068em}}}
\begin{document}
With \texttt{makecell}: 
\begin{table}[!h]
\centering
\setcounter{rowno}{0}
\caption{Comparison of Groups A and B}\label{AB}
\begin{tabular}{>{\refstepcounter{rowno}\,\therowno}c*{7}{S[table-format=1.3]}}%{}
\toprule
\emptycell & & \multicolumn{3}{c}{Group A} &\multicolumn{3}{c@{}}{Group B}\\
\cmidrule(lr){3-5} \cmidrule(lr){6-8}
\multicolumn{1}{c}{\thead{\\\No}} & {\thead{A\\}}& {\thead{A\\(unit)}} &{ \thead{B\\}} &{\thead{C\\(unit)}} & {\thead{A\\(unit)}}& {\thead{B}} & {\thead{C\\(unit)}}\\
\cmidrule[\lightrulewidth](lr){1-8}
\addlinespace[1.2ex]
& 0.751 & 0.498 & 0.706 & 0.823 & 0.439 & 0.490 & 0.276\\
& 0.255 & 0.960 & 0.032 & 0.695 & 0.382 & 0.446 & 0.680\\
& 0.506 & 0.340 & 0.277 & 0.317 & 0.766 & 0.646 & 0.655\\
& 0.699 & 0.585 & 0.046 & 0.950 & 0.795 & 0.709 & 0.163\\
& 0.891 & 0.224 & 0.097 & 0.034 & 0.187 & 0.755 & 0.119\\
\bottomrule
\end{tabular}
\end{table}
\vskip 1cm
With \texttt{stackengine}:
\begin{table}[!h]
\centering
\setcounter{rowno}{0}
\caption{Comparison of Groups A and B}\label{AB}
\begin{tabular}{@{}>{\refstepcounter{rowno}\,\therowno}c*{7}{c}}%{}S[table-format=1.3]
\toprule
\emptycell & & \multicolumn{3}{c}{Group A} &\multicolumn{3}{c@{}}{Group B}\\
\cmidrule(lr){3-5} \cmidrule(lr){6-8}
\multicolumn{1}{c}{\stackunder{}{\No}} & {A} & {\stackunder{A}{(unit)}} & {B} &
{\stackunder{C}{(unit)}} & {\stackunder{A}{(unit)}}& {B} & {\stackunder{C}{(unit)}}\\
\addlinespace
\cmidrule[\lightrulewidth](lr){1-8}
\addlinespace[1.2ex]
& 0.751 & 0.498 & 0.706 & 0.823 & 0.439 & 0.490 & 0.276\\
& 0.255 & 0.960 & 0.032 & 0.695 & 0.382 & 0.446 & 0.680\\
& 0.506 & 0.340 & 0.277 & 0.317 & 0.766 & 0.646 & 0.655\\
& 0.699 & 0.585 & 0.046 & 0.950 & 0.795 & 0.709 & 0.163\\
& 0.891 & 0.224 & 0.097 & 0.034 & 0.187 & 0.755 & 0.119\\
\bottomrule
\end{tabular}
\end{table}

\end{document} 

enter image description here

You must log in to answer this question.

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