Graphics, Figures & TablesHelp needed with using multirow and multicolumn

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ShaunnaH
Posts: 3
Joined: Mon Apr 25, 2011 6:31 pm

Help needed with using multirow and multicolumn

Post by ShaunnaH »

I've been trying to figure out the answer to this formatting issue for a while now. I've searched and I couldn't find anybody with my exact problem. Using the code below, the table comes out structured correctly with one small problem: the cell color doesn't fill the multirow cell and then some thing wacky is going on with the header cell for the last column

Code: Select all

\multirow{2}{*}{\cellcolor[gray]{0.85}\textbf{Category}} & \multicolumn{4}{|c}{\cellcolor[gray]{0.85}\textbf{Parameter}} & \multicolumn{4}{|c|}{\cellcolor[gray]{0.85}\textbf{Parameter}}\\\cline{2-9}
& \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter}& \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter}\\ \endfirsthead \hline
\multirow{2}{*}{\cellcolor[gray]{0.85}\textbf{Category}} & \multicolumn{4}{|c}{\cellcolor[gray]{0.85}\textbf{Parameter}} & \multicolumn{4}{|c|}{\cellcolor[gray]{0.85}\textbf{Parameter}}\\\cline{2-9}
& \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter}& \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter}\\ \endhead \hline
\multicolumn{9}{|c|}{\cellcolor[gray]{0.85}\textbf{Divider}}\\ \hline
Noun&value&value&value&value&value&value&value&value\\ \hline
Noun&value&value&value&value&value&value&value&value\\ \hline
\multicolumn{9}{|c|}{\cellcolor[gray]{0.85}\textbf{Divider}}\\
\hline
Noun&value&value&value&value&value&value&value&value\\ \hline
Noun&value&value&value&value&value&value&value&value\\ \hline
\multicolumn{9}{|c|}{\cellcolor[gray]{0.85}\textbf{Divider}}\\
\hline
Noun&value&value&value&value&value&value&value&value\\ \hline
Noun&value&value&value&value&value&value&value&value\\ \hline
\multicolumn{9}{|>{\raggedright\arraybackslash}p{7.25in}|}{Very very very very very very very very very very very very very very very very very very very very very very very very long table notes. Etc }\\ 
\hline
Here's an example of the table.
Here's an example of the table.
table.jpg (138.13 KiB) Viewed 3700 times
Last edited by ShaunnaH on Mon Apr 25, 2011 10:06 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Help needed with using multirow and multicolumn

Post by Stefan Kottwitz »

Hi ShaunnaH,

welcome to the board!
Those code lines don't show much information. For example, the column declaration is missing. The best chance to get help is to post a complete minimal working example - compilable. So every reader could test it.

Without such information, I could offer just general advice. Those many vertical lines, framing each cell, makes a table less readable. In good book, it's common to use horizontal lines but to avoid vertical lines which make reading harder. Some coloring can be ok, if it supports the information. Though multirow is a bit delicate in general and doesn't work fine with all possible table features.

Here are some examples using \multirow and \multicolumn, further loading booktabs to get nicer looking tables - perhaps check the table at the and of that article: Creating tables with LaTeX.
LaTeX.org admin
ShaunnaH
Posts: 3
Joined: Mon Apr 25, 2011 6:31 pm

Help needed with using multirow and multicolumn

Post by ShaunnaH »

Stefan,

Thanks for your response. The tables need to look that way because of office politics. Long story short, the readers of this document are used to information being presented in a certain way and I'm trying to recreate that in LaTeX as best I can. So far, I've been able to work around the other formatting errors I've had. This is the only thorn in my side, so to speak.

Here's the full table declaration:

Code: Select all

\begin{center}
{\small \begin{longtable}[c]{|m{1.25in}|>{\centering\arraybackslash}m{0.5in}|>{\centering\arraybackslash}m{0.5in}|>{\centering\arraybackslash}m{0.5in}|>{\centering\arraybackslash}m{0.75in}|>{\centering\arraybackslash}m{0.5in}|>{\centering\arraybackslash}m{0.5in}|>{\centering\arraybackslash}m{0.5in}|>{\centering\arraybackslash}m{0.75in}|}
\caption[Table Caption]{Table Caption} \label{TableLabel}\\
\hline
\multirow{2}{*}{\cellcolor[gray]{0.85}\textbf{Category}} & \multicolumn{4}{|c}{\cellcolor[gray]{0.85}\textbf{Parameter}} & \multicolumn{4}{|c|}{\cellcolor[gray]{0.85}\textbf{Parameter}}\\\cline{2-9}
& \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter}& \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter}\\ \endfirsthead \hline
\multirow{2}{*}{\cellcolor[gray]{0.85}\textbf{Category}} & \multicolumn{4}{|c}{\cellcolor[gray]{0.85}\textbf{Parameter}} & \multicolumn{4}{|c|}{\cellcolor[gray]{0.85}\textbf{Parameter}}\\\cline{2-9}
& \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter}& \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter} & \cellcolor[gray]{0.85}\textbf{Parameter}\\ \endhead \hline
\multicolumn{9}{|c|}{\cellcolor[gray]{0.85}\textbf{Divider}}\\ \hline
Noun&value&value&value&value&value&value&value&value\\ \hline
Noun&value&value&value&value&value&value&value&value\\ \hline
\multicolumn{9}{|c|}{\cellcolor[gray]{0.85}\textbf{Divider}}\\
\hline
Noun&value&value&value&value&value&value&value&value\\ \hline
Noun&value&value&value&value&value&value&value&value\\ \hline
\multicolumn{9}{|c|}{\cellcolor[gray]{0.85}\textbf{Divider}}\\
\hline
Noun&value&value&value&value&value&value&value&value\\ \hline
Noun&value&value&value&value&value&value&value&value\\ \hline
\multicolumn{9}{|>{\raggedright\arraybackslash}p{7.25in}|}{Very very very very very very very very very very very very very very very very very very very very very very very very long table notes. Etc }\\ 
\hline
\end{longtable} }
\end{center}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Help needed with using multirow and multicolumn

Post by Stefan Kottwitz »

If the design is required, than is has to be done so. :-) That's fine.

You could use the array package for easier work. For example, this way the column declaration is much easier to read and to handle:

Code: Select all

\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
...
\begin{longtable}[c]{|m{1.25in}*3{|C{0.5in}}|C{0.75in}*3{|C{0.5in}|C{0.75in}}|}
...
I guess there are header problems because the columns are too narrow. I would adjust their width or their contents. Regarding the colored multirow cell, the package documentation tells about that issue at the end of the text. Just type texdoc multirow or open multirow.sty.

Stefan
LaTeX.org admin
ShaunnaH
Posts: 3
Joined: Mon Apr 25, 2011 6:31 pm

Re: Help needed with using multirow and multicolumn

Post by ShaunnaH »

Thanks for the advice.

I'd tried the negative "nrows" declaration before but it didn't work. But now I figured out the issue. For some reason, I still needed to specify the cell color for the "empty" part of the multirow cell.
Post Reply