Generalhelp with table (multirow)

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
sombrancelha
Posts: 22
Joined: Fri May 18, 2007 6:48 pm

help with table (multirow)

Post by sombrancelha »

Hi,

Can someone please help me?

I'm having some difficulties to build up a table, it should look like this:

__________
|_|___|__|
|_|___|__|

It's a regular column, then a 2 row column, and then another regular column.

Hope I've been clear enough, if not, please tell me.

Thank you

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
balfonsi
Posts: 93
Joined: Wed Mar 14, 2007 12:05 am

Re: help with table (multirow)

Post by balfonsi »

No quite. What do you mean exactly by a 'regular column'? A 'row' is a series of cells horizontally aligned, and what you describe seems to be columns of a certain width, and others twice as wide. Right?
If that is the case, either choose the widths (e.g. p(15mm) and p(30mm) but the content will appear as a paragraph. Or you choose the total width of your table, and use the tabularx environment; every column of X type will have a width equal to total width:number of columns; and you still can have columns of width equal to a fixed fraction of the X width (with certain limitations, see the doc of tabularx).

Hope I've been reasonably clear. If not, you should be more precise as for your requirements.

Regards,
B.A.
sombrancelha
Posts: 22
Joined: Fri May 18, 2007 6:48 pm

help with table (multirow)

Post by sombrancelha »

Hi,

Sorry if I haven't been clear. What I mean is a table like this:

Image

How can I do that?

Thank you
balfonsi
Posts: 93
Joined: Wed Mar 14, 2007 12:05 am

Re: help with table (multirow)

Post by balfonsi »

Use multirow package.

Here's a sample based on your example:

\newcolumntype{C}{>{\centering}p{12mm}@{}}

\begin{tabular}{|C|c|C|C|}
\hline%
1A &\multirow{2}{12mm}{\centering W} & 1 & 2 \tabularnewline
\cline{1-1} \cline{3-4}%
2A & & 2 & 6 \tabularnewline
\hline%
1B& \multirow{2}{12mm}{X} & 3 & 7 \tabularnewline
\cline{1-1} \cline{3-4}%
2B && 4& 8 \tabularnewline
\hline%
\end{tabular}

I had to inser \tabularnewline rather than \\ at the end of the rows because of an error message in the latter case (a conflict with multirow?).

You also should look at a new package called makecell, whch "eases the use of multirow", according to its author, and extends the possibilities.

Regards,
B.A.
User avatar
countbela666
Posts: 64
Joined: Thu Apr 26, 2007 2:44 pm

help with table (multirow)

Post by countbela666 »

balfonsi wrote: I had to inser \tabularnewline rather than \\ at the end of the rows because of an error message in the latter case (a conflict with multirow?).
This is a side effect of the array package, as it redefines the \\ command. When trying to use an own column type that uses the >{...} or <{...} constructions as last column of a tabular environment you will get an error. You can avoid this either by using \tabularnewline to enter a line break or by including \arraybackslash into your column type definition:

Code: Select all

\newcolumntype{C}{>{\centering\arraybackslash}p{12mm}}
BTW: why do you cut off the \tabcolsep in your column definition by including @{}? I think it looks nicer without this.

Regards
Marcel
Listen to me children of the night, beyond the doors of darkness you will find
a thousand worlds for you to see here, take my hand and follow me...
balfonsi
Posts: 93
Joined: Wed Mar 14, 2007 12:05 am

Re: help with table (multirow)

Post by balfonsi »

I insert @{} for the last column 'cause otherwise, the hlines go a little further than the last vertical one (another side effect?)

B.A.
User avatar
countbela666
Posts: 64
Joined: Thu Apr 26, 2007 2:44 pm

Re: help with table (multirow)

Post by countbela666 »

I cannot see a difference between both versions concerning the line lengths. In the PDF viewer the horizontal lines seem to exceed the width of the table by a fraction of a millimeter -- but this seems to depend on the zoom factor and it has no effect on the printed document.

Regards
Marcel
Listen to me children of the night, beyond the doors of darkness you will find
a thousand worlds for you to see here, take my hand and follow me...
balfonsi
Posts: 93
Joined: Wed Mar 14, 2007 12:05 am

Re: help with table (multirow)

Post by balfonsi »

You're perfectly right. I don't know what happened exactly. Usually, I perform tests like that with an old file that has been used for a previousstest, deleting what is useless or incompatible. As I don't remember exactly what I've modified, I can't tell more. Anyway, everything is OK now.

B.A.
Post Reply