Graphics, Figures & Tablesmultirow with several columns

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
fedner
Posts: 5
Joined: Thu Aug 18, 2011 4:47 pm

multirow with several columns

Post by fedner »

Hi. I need to create a table with 4 columns. In the 4th column, for each row, i want to insert n rows, where n varies for each "master" row. To make a comparison, it's like if i wanted to split a cell in several rows in a table of a text editor like Word. What i want is something like this:

Image

I tried to use in several ways the \multirow command, but all i can obtain is a single column before the multiple rows:

Image

With \newcommand i can embed a table in the first cell, but the vertical lines refer to the embedded table and so the result is horrible:

Image

A solution i found is to use a description list in the last cell, instead of rows. But, if anyone knows a better way to do this, any suggestion will be very appreciated.
Thanks in advance.

Fedner

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

multirow with several columns

Post by Stefan Kottwitz »

Hi Fedner,

welcome to the board!

Besides \multirow, you could use \cline. Here's an example:

Code: Select all

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|c|}
\hline
Col1 & Col2 & Col3 & Col4 \\\hline
\multirow{4}{*}{Text} & & & \\\cline{4-4}
 & & & \\\cline{4-4}
 & & & \\\cline{4-4}
 & & & \\\hline
\multirow{3}{*}{Text} & & & \\\cline{4-4}
 & & & \\\cline{4-4}
 & & & \\\hline
\end{tabular}
\end{document}
Stefan
LaTeX.org admin
fedner
Posts: 5
Joined: Thu Aug 18, 2011 4:47 pm

multirow with several columns

Post by fedner »

Stefan_K wrote:Hi Fedner,

welcome to the board!
Thank you :)
Stefan_K wrote:Besides \multirow, you could use \cline.
Thanks for your help. I tried your code putting some text in cells. This is the result:

Image

As you can see, the description written in Col3 takes a lot of space, and this is my biggest problem because entries in Col4 are badly aligned. It would be wonderful if i could merge rows in first three columns but not the in fourth.
Ah, i was forgetting an important detail: since my table has a lot of entries with long text in Col3, I'm using xtab package to generate a table that need to be splitted in several pages.

Bye

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

multirow with several columns

Post by Stefan Kottwitz »

Hi Fedner,

perhaps post a compilable minimal example, so we all know what we are speaking about and are able to work with the code.

Regarding column 3: of course you can use \multirow also in several columns, such as

Code: Select all

\multirow{4}{*}{Text} & \multirow{4}{*}{more Text} &
    \multirow{4}{*}{very long Text} & \\\cline{4-4}
Stefan
LaTeX.org admin
fedner
Posts: 5
Joined: Thu Aug 18, 2011 4:47 pm

multirow with several columns

Post by fedner »

Stefan_K wrote:perhaps post a compilable minimal example, so we all know what we are speaking about and are able to work with the code.

Regarding column 3: of course you can use \multirow also in several columns, such as

Code: Select all

\multirow{4}{*}{Text} & \multirow{4}{*}{more Text} &
    \multirow{4}{*}{very long Text} & \\\cline{4-4}
Stefan
Oh yes, sorry, i'll give you some code :P

I tried out your suggestion in a sample table and nested multirow commands. The code i have written is the following:

Code: Select all

\begin{tabular}{| p{2,5cm} | p{2cm} | p{4cm} | p{4,5cm} |}
\hline
\multirow{4}{2,5cm}{Stufa} & \multirow{4}{2cm}{Sinonimo di Stufa} &
    \multirow{4}{4cm}{Prodotto composito destinato al riscaldamento di un ambiente. Molto semplicisticamente, bruciando combustibile (nella fattispecie, \emph{pellet}) produce calore, che viene diffuso nell'ambiente. Si può scomporre macroscopicamente in una \emph{carrozzeria} ed in un \emph{corpo caldaia}.} 
    & haComponente Carrozzeria1 \\\cline{4-4}
    & haComponente Carrozzeria2 \\\cline{4-4}
    & haComponente Carrozzeria3 \\\cline{4-4}
    & haComponente Carrozzeria4 \\\cline{4-4}
\hline
\end{tabular}
Unfortunatly, the result is still bad:

Image

It seems like if second, third and fourth entries refer to the first multirow command... can be this the problem? If yes, how can i solve it having no brackets to delimit the scope of each command?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

multirow with several columns

Post by Stefan Kottwitz »

Don't forget the & symbols for the empty cells in the next rows:

Code: Select all

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{| p{2,5cm} | p{2cm} | p{4cm} | p{4,5cm} |}
\hline
\multirow{4}{2,5cm}{Stufa} & \multirow{4}{2cm}{Sinonimo di Stufa} &
      \multirow{4}{4cm}{Prodotto composito destinato al riscaldamento di un ambiente.}
      & haComponente Carrozzeria1 \\\cline{4-4}
    & & & haComponente Carrozzeria2 \\\cline{4-4}
    & & & haComponente Carrozzeria3 \\\cline{4-4}
    & & & haComponente Carrozzeria4 \\\cline{4-4}
\hline
\end{tabular}
\end{document}
table.png
table.png (17.65 KiB) Viewed 17260 times
Stefan
LaTeX.org admin
fedner
Posts: 5
Joined: Thu Aug 18, 2011 4:47 pm

multirow with several columns

Post by fedner »

Stefan_K wrote:Don't forget the & symbols for the empty cells in the next rows
Oh yes, I've been so silly! I tried to enter & symbols but i did it in the wrong way...

Ok, we are near to the goal. The only thing that still distress me is the length of text in cells: using a long text like in the code below, I see in the pdf the text going over the bottom line of the row. You can see the result in the attachment.

Code: Select all

\begin{tabular}{| p{2,5cm} | p{2cm} | p{4cm} | p{4,5cm} |}
\hline
\multirow{4}{2,5cm}{Stufa} & \multirow{4}{2cm}{Sinonimo di Stufa} &
      \multirow{4}{4cm}{Prodotto composito destinato al riscaldamento di un ambiente. Molto semplicisticamente, bruciando combustibile (nella fattispecie, \emph{pellet}) produce calore, che viene diffuso nell'ambiente. Si può scomporre macroscopicamente in una \emph{carrozzeria} ed in un \emph{corpo caldaia}.}
      & haComponente Carrozzeria1 \\\cline{4-4}
    & & & haComponente Carrozzeria2 \\\cline{4-4}
    & & & haComponente Carrozzeria3 \\\cline{4-4}
    & & & haComponente Carrozzeria4 \\\cline{4-4}
\hline
\end{tabular}
The row fits to the height of the fourth cell, and maybe this is the best behavior in most cases, but is there a way to change it without adding empty rows in the multirow command? I can use this trick:

Code: Select all

\begin{tabular}{| p{2,5cm} | p{2cm} | p{5cm} | p{3,5cm} |}
\hline
\multirow{8}{2,5cm}{Stufa} & \multirow{8}{2cm}{Sinonimo di Stufa} &
      \multirow{8}{5cm}{Prodotto composito destinato al riscaldamento di un ambiente. Molto semplicisticamente, bruciando combustibile (nella fattispecie, \emph{pellet}) produce calore, che viene diffuso nell'ambiente. Si può scomporre macroscopicamente in una \emph{carrozzeria} ed in un \emph{corpo caldaia}.}
      & haComponente Carrozzeria1 \\
    & & & haComponente Carrozzeria2 \\
    & & & haComponente Carrozzeria3 \\
    & & & haComponente Carrozzeria4 \\
    & & & \\
    & & & \\
    & & & \\
    & & & \\
\hline
\end{tabular}
but it's quite laborious and expensive for a big table.

Thank you for your patience.

Fedner
Attachments
suggestion3.jpg
suggestion3.jpg (53.46 KiB) Viewed 17257 times
fedner
Posts: 5
Joined: Thu Aug 18, 2011 4:47 pm

Re: multirow with several columns

Post by fedner »

Another issue: the xtab environment splits a big table in several pages; unfortunately, multirow block is splitted in two parts if the page break comes in the middle. I'd like to keep it whole. Is it possible?
In attachment, a sample file.

Thanks

Fedner
Attachments
source_samples.tex
(3.88 KiB) Downloaded 396 times
Post Reply