Developers, Developers, Developers! Maksim Sorokin IT Blog

22May/10Off

Multirow and Multicolumn Spanning in Latex

Miltirow and multicolumn table spanning now with colors!

or more complex example:

And here how we do that for simple variant:

\documentclass[12pt]{article}
\usepackage{multirow}
\usepackage{colortbl}
\definecolor{kugray5}{RGB}{224,224,224}

\begin{document}

\begin{figure}
  \centering
  \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
    \hline
    \multicolumn{1}{|>{\columncolor{kugray5}}c|}{}&\multicolumn{4}{c|}{Rank}&\multirow{2}{*}{Total}\\
    \arrayrulecolor{kugray5}
    \arrayrulecolor{black}
    \cline{2-5}
    \multicolumn{1}{|>{\columncolor{kugray5}}c|}{}&A&B&C&Other&\\
    \hline
    type 2&8&14&5&2&29\\
    \hline
  \end{tabular}
  \caption{Distribution of the types by rank}
  \label{fig:typeDistribution}
\end{figure}

\end{document}

And for more complex one:

\documentclass[12pt]{article}
\usepackage{multirow}
\usepackage{colortbl}
\definecolor{kugray5}{RGB}{224,224,224}

\begin{document}

\begin{figure}
  \centering
  \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
    \hline
    \multicolumn{2}{|>{\columncolor{kugray5}}c|}{}&\multicolumn{4}{c|}{Rank}&\multirow{2}{*}{Total}\\
    \arrayrulecolor{kugray5}
    \arrayrulecolor{black}
    \cline{3-6}
    \multicolumn{2}{|>{\columncolor{kugray5}}c|}{}&A&B&C&Other&\\
    \hline
    \multirow{2}{*}{Type}&type 1&10&21&6&3&40\\
    \cline{2-7}
                         &type 2&8&14&5&2&29\\
    \hline
    \multicolumn{2}{|c|}{Total}&18&35&11&5&69\\
    \hline
  \end{tabular}
  \caption{Distribution of the types by rank}
  \label{fig:typeDistribution}
\end{figure}

\end{document}
Tagged as: , Comments Off
Comments (2) Trackbacks (0)
  1. The first version won’t render under Gummi. Error says:
    Runaway argument?
    |
    /tmp/gummi_WKKZVV:12: Forbidden control sequence found while scanning use of \N
    C@find.

    \par
    l.12 …olumn{1}{|>{\columncolor{kugray5}}c|}{}
    &\multicolumn{4}{c|}{Rank}…
    No pages of output.
    Transcript written on /tmp/gummi_WKKZVV.log.

  2. Sorry, something went wrong with several escaped characters in the code listings after update. Now this should work.


Leave a comment


Trackbacks are disabled.