4

I'm trying to create a table which some of the cells are multirow and this is my code:

\begin{table}[!htb]
\centering
\small\addtolength{\tabcolsep}{4pt}
\caption{""}
\label{table3}
\begin{tabular}{*{7}{|c}|}
\hline
 \multirow{2}{*}{H}& \multicolumn{3}{c|}{K@10} & \multicolumn{3}{c|}{K@20}\\\cline{2-7}
 & P & R & TFFR &  P & R & TFFR  \\\hline 
H\textsubscript{01}  & \multirow{2}{*} & \multirow{2}{*} & \multirow{2}{*} & \multirow{2}{*} & \multirow{2}{*}  & \multirow{2}{*}  \\\hline
H\textsubscript{02} & & & & & &  \\
H\textsubscript{03}  & \multirow{2}{*}  & \multirow{2}{*} & \multirow{2}{*} & \multirow{2}{*} & \multirow{2}{*}  & \multirow{2}{*}   \\\hline
H\textsubscript{04} & & & & & &  \\
H\textsubscript{05}  & \multirow{2}{*}  & \multirow{2}{*}  & \multirow{2}{*} & \multirow{2}{*} & \multirow{2}{*}  & \multirow{2}{*}  \\\hline
H\textsubscript{06} & & & & & &  \\\hline
 \end{tabular}
\end{table}

I don't know what's wrong with this code. This is the error which I got:

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.487 ... & \multirow{2}{*}  & \multirow{2}{*}  \\
  • 1
    \multirow takes three mandatory arguments: rows, width, and text. You consistently miss the third argument. – Mike Renfro Feb 4 '14 at 23:16
  • thanks, I don't want to have a text in my cell, I just want to have a colored cell, what should I do? – sarah Feb 4 '14 at 23:22
  • 1
    Use \multirow{2}{*}{\cellcolor{<your color>}} with \usepackage[table]{xcolor} loaded. – Jesse Feb 4 '14 at 23:39
5

Let us list the errors first.

  1. For quotation marks you shouldn't use "..." but ``...''
  2. \multirow{2}{*}{H} takes three arguments - \multirow{<rows>}{<width>}{<content>}. You have missed the third argument. Even if you don't want to have text, you should have it but without content like \multirow{2}{*}{}.
  3. \textsubscript isn't defined by LaTeX. You have to use \usepackage{fixltx2e} in the preamble to make it work. BTW are you trying to write a chemical formula? If so, there are packages meant for that job. Or are those H\textsubscript{02}s mathematical variables? Please elaborate.
  4. To make colored cells, load colortbl package or usepackage[table]{xcolor} (Both are equivalent). and the use \cellcolor{<color> inside the cell:

    & \cellcolor{green!50!blue} <content> &
    

    or

     & \cellcolor{green!50!blue}\multirow{2}{*}{}  &
    
  5. Do you really want vertical lines? What about reducing the number of some horizontal lines? You may read the documentation of booktabs package to learn how to produce a good table.

Now your code should be:

\documentclass{article}
\usepackage{multirow,fixltx2e}
\usepackage[table]{xcolor}    %% this in turn loads colortbl
%\usepackage{colortbl}
\begin{document}
  \begin{table}[!htb]
\centering
\small\addtolength{\tabcolsep}{4pt}
\caption{``''}
\label{table3}
\begin{tabular}{*{7}{|c}|}
\hline
 \multirow{2}{*}{H}& \multicolumn{3}{c|}{K@10} & \multicolumn{3}{c|}{K@20}\\\cline{2-7}
 & P & R & TFFR &  P & R & TFFR  \\\hline
H\textsubscript{01}  & \multirow{2}{*}{} & \multirow{2}{*}{}& \multirow{2}{*}{} & \multirow{2}{*}{} & \multirow{2}{*} {} & \multirow{2}{*}{}  \\\hline
H\textsubscript{02} & \cellcolor{green!50!blue} & & & & &  \\
H\textsubscript{03}  & \cellcolor{green!50!blue}\multirow{2}{*}{}  & \multirow{2}{*}{} & \multirow{2}{*}{} & \multirow{2}{*}{} & \multirow{2}{*}{}  & \multirow{2}{*}{}   \\\hline
H\textsubscript{04} & & \cellcolor{green!50!blue} & & & &  \\
H\textsubscript{05}  & \multirow{2}{*}{}  & \cellcolor{green!50!blue}\multirow{2}{*}{}  & \multirow{2}{*}{} & \multirow{2}{*}{} & \multirow{2}{*}{}  & \multirow{2}{*}{}  \\\hline
H\textsubscript{06} & & & & & &  \\\hline
 \end{tabular}
\end{table}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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