Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

nested table using multirow/multicolumn

247 views
Skip to first unread message

Sharon Kimble

unread,
Jan 28, 2016, 8:42:36 AM1/28/16
to

How can I have a nested table in a longtable which will give me results
like this please -

--8<---------------cut here---------------start------------->8---
Gender / Hormone | Range
-----------------------------------------------------------
Estradiol - E2
-----------------------------------------------------------
Male | 0.5-1.5 pg/ml
-----------------------------------------------------------
| Pre-menopausal 1.0-5.0 pg/ml
Female | Post-menopausal 1.0-1.5 pg/ml
| ERT therapy 1.5-10.0 pg/ml
-----------------------------------------------------------
Another hormone back in the longtable
--8<---------------cut here---------------end--------------->8---

This is my MWE which does =not= work

--8<---------------cut here---------------start------------->8---
\documentclass{article}
\usepackage{multirow}
\begin{document}

\begin{longtable}{| p{5.5cm} | p{3cm} |}
\hline
\textbf{Gender / Hormone} & \textbf{Range} \\
\hline
\multicolumn{2}{|l|}{\textbf{Estradiol - E2}} \\
\hline
Male & 0.5--1.5 pg/ml \\
\begin{tabular}{l|cc}
\hline
\multirow{3}{*}{\textbf{Female}} & \multicolumn{2}{c}{Pre-menopausal & 1.0--5.0 pg/ml} \\
& Post-menopausal & 1.0--1.5 pg/ml \\
& ERT therapy & 1.5--10.0pg/ml \\
\hline
\end{tabular}
\end{longtable}

\end{document}
--8<---------------cut here---------------end--------------->8---

I have tried various things but none of them work, so how can I do it
please?

Thanks
Sharon.
--
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
Debian 8.3, fluxbox 1.3.7, emacs 24.5.1
signature.asc

Peter Flynn

unread,
Jan 28, 2016, 6:21:19 PM1/28/16
to
On 01/28/2016 01:42 PM, Sharon Kimble wrote:
>
> How can I have a nested table in a longtable which will give me results
> like this please -
>
> --8<---------------cut here---------------start------------->8---
> Gender / Hormone | Range
> -----------------------------------------------------------
> Estradiol - E2
> -----------------------------------------------------------
> Male | 0.5-1.5 pg/ml
> -----------------------------------------------------------
> | Pre-menopausal 1.0-5.0 pg/ml
> Female | Post-menopausal 1.0-1.5 pg/ml
> | ERT therapy 1.5-10.0 pg/ml
> -----------------------------------------------------------
> Another hormone back in the longtable
> --8<---------------cut here---------------end--------------->8---
>
> This is my MWE which does =not= work

Like all the best MWEs. We ought to rename them MNWEs.

> --8<---------------cut here---------------start------------->8---
> \documentclass{article}
> \usepackage{multirow}

Missing longtable, but I'm sure you had that.

> \begin{document}
>
> \begin{longtable}{| p{5.5cm} | p{3cm} |}
> \hline
> \textbf{Gender / Hormone} & \textbf{Range} \\
> \hline
> \multicolumn{2}{|l|}{\textbf{Estradiol - E2}} \\
> \hline
> Male & 0.5--1.5 pg/ml \\

The following tabular environment will fill only the first cell, the
5.5cm one. If you want it to span across both cells, it needs to go
inside a \multicolumn2l but that becomes ungainly to code.

> \begin{tabular}{l|cc}
> \hline
> \multirow{3}{*}{\textbf{Female}} & \multicolumn{2}{c}{Pre-menopausal & 1.0--5.0 pg/ml} \\

That & after "Pre-menopausal" needs to be escaped as \&

> & Post-menopausal & 1.0--1.5 pg/ml \\
> & ERT therapy & 1.5--10.0pg/ml \\
> \hline
> \end{tabular}
> \end{longtable}
>
> \end{document}

The architecture of complex tables usually has several solutions. I'm
going to suggest one here that simplifies the code, but as I don't know
the content of the rest of the table, it may be inappropriate.

1. Use the array package and make the cells m{width} which will have the
effect of vertically-centering their content. Otherwise they behave like
p{width}.

2. Your emebedded tabular is anyway far too wide to fit your 3cm cell so
I have switched the widths around and widened the first one.

3. Now you don't need multirow any more.

4. Fixed the \& problem.

5. Added a new strut to create a fraction more space above the top line
of each cell, otherwise the table looks very cramped. This goes in the
column specification prefix >{...} before each one. I have used the
normal \strut in the embedded tabular as it doesn't need the extra height.

6. The embedded tabular needed the left-hand shoulded annulling with @{}

\documentclass{article}
\usepackage{longtable,array}
\newcommand{\vstrut}{\vrule height1.05em width0pt depth0pt}
\begin{document}

\begin{longtable}{| >{\vstrut}m{3.5cm} | >{\vstrut}m{5.5cm} |}
\hline
\textbf{Gender / Hormone} & \textbf{Range} \\
\hline
\multicolumn{2}{|>{\vstrut}l|}{\textbf{Estradiol - E2}} \\
\hline
Male & 0.5--1.5 pg/ml \\
\hline
\textbf{Female}& \begin{tabular}{@{}>{\strut}l|cc}
Pre-menopausal & 1.0--5.0 pg/ml \\
Post-menopausal & 1.0--1.5 pg/ml \\
ERT therapy & 1.5--10.0pg/ml \\
\end{tabular}\\
\hline
\end{longtable}

\end{document}

///Peter



Sharon Kimble

unread,
Jan 29, 2016, 1:33:40 PM1/29/16
to
Peter Flynn <pe...@silmaril.ie> writes:

> On 01/28/2016 01:42 PM, Sharon Kimble wrote:
>>
>> How can I have a nested table in a longtable which will give me results
>> like this please -
>>
>> --8<---------------cut here---------------start------------->8---
>> Gender / Hormone | Range
>> -----------------------------------------------------------
>> Estradiol - E2
>> -----------------------------------------------------------
>> Male | 0.5-1.5 pg/ml
>> -----------------------------------------------------------
>> | Pre-menopausal 1.0-5.0 pg/ml
>> Female | Post-menopausal 1.0-1.5 pg/ml
>> | ERT therapy 1.5-10.0 pg/ml
>> -----------------------------------------------------------
>> Another hormone back in the longtable
>> --8<---------------cut here---------------end--------------->8---
>>
>> This is my MWE which does =not= work
>
> Like all the best MWEs. We ought to rename them MNWEs.

:)
>
>> --8<---------------cut here---------------start------------->8---
>> \documentclass{article}
>> \usepackage{multirow}
>
> Missing longtable, but I'm sure you had that.

True, I did forget to put it in.
>
>> \begin{document}
>>
>> \begin{longtable}{| p{5.5cm} | p{3cm} |}
>> \hline
>> \textbf{Gender / Hormone} & \textbf{Range} \\
>> \hline
>> \multicolumn{2}{|l|}{\textbf{Estradiol - E2}} \\
>> \hline
>> Male & 0.5--1.5 pg/ml \\
>
> The following tabular environment will fill only the first cell, the
> 5.5cm one. If you want it to span across both cells, it needs to go
> inside a \multicolumn2l but that becomes ungainly to code.
>
>> \begin{tabular}{l|cc}
>> \hline
>> \multirow{3}{*}{\textbf{Female}} & \multicolumn{2}{c}{Pre-menopausal & 1.0--5.0 pg/ml} \\
>
> That & after "Pre-menopausal" needs to be escaped as \&
>
>> & Post-menopausal & 1.0--1.5 pg/ml \\
>> & ERT therapy & 1.5--10.0pg/ml \\
>> \hline
>> \end{tabular}
>> \end{longtable}
>>
>> \end{document}
>
> The architecture of complex tables usually has several solutions. I'm
> going to suggest one here that simplifies the code, but as I don't know
> the content of the rest of the table, it may be inappropriate.

I was able to use your code and add other stuff to it to build the whole
table.
>
> 1. Use the array package and make the cells m{width} which will have the
> effect of vertically-centering their content. Otherwise they behave like
> p{width}.

I didn't know of the package "array", thanks.
>
> 2. Your emebedded tabular is anyway far too wide to fit your 3cm cell so
> I have switched the widths around and widened the first one.
>
> 3. Now you don't need multirow any more.
>
> 4. Fixed the \& problem.
>
> 5. Added a new strut to create a fraction more space above the top line
> of each cell, otherwise the table looks very cramped. This goes in the
> column specification prefix >{...} before each one. I have used the
> normal \strut in the embedded tabular as it doesn't need the extra
> height.

\strut is unknown by me, what package is it in please so I can learn
more about it?
>
> 6. The embedded tabular needed the left-hand shoulded annulling with @{}
>
> \documentclass{article}
> \usepackage{longtable,array}
> \newcommand{\vstrut}{\vrule height1.05em width0pt depth0pt}
> \begin{document}
>
> \begin{longtable}{| >{\vstrut}m{3.5cm} | >{\vstrut}m{5.5cm} |}
> \hline
> \textbf{Gender / Hormone} & \textbf{Range} \\
> \hline
> \multicolumn{2}{|>{\vstrut}l|}{\textbf{Estradiol - E2}} \\
> \hline
> Male & 0.5--1.5 pg/ml \\
> \hline
> \textbf{Female}& \begin{tabular}{@{}>{\strut}l|cc}
> Pre-menopausal & 1.0--5.0 pg/ml \\
> Post-menopausal & 1.0--1.5 pg/ml \\
> ERT therapy & 1.5--10.0pg/ml \\
> \end{tabular}\\
> \hline
> \end{longtable}
>
> \end{document}

That works extremely well, thanks very much.
>
> ///Peter
>
Thanks
Sharon.
--
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
Debian 8.3, fluxbox 1.3.7, emacs 25.0.50.2
signature.asc

Peter Flynn

unread,
Jan 29, 2016, 5:39:30 PM1/29/16
to
On 01/29/2016 06:33 PM, Sharon Kimble wrote:
> Peter Flynn <pe...@silmaril.ie> writes:
[...]
> I was able to use your code and add other stuff to it to build the
> whole table.

Cool. I wasn't expecting it to work with everything else.

> I didn't know of the package "array", thanks.

It's very handy, mainly for the m and b column types, and for the
> {...} and <{...} prefixes and suffixes that avoid a lot of
> repetitive
formatting code in the data.

> \strut is unknown by me, what package is it in please so I can
> learn more about it?

It's in the TeX and LaTeX kernels AFAIR. It's just a \vrule protruding
70% of the line-height up and 30% of it down, and no width (so it's
invisible). It can be used to compensate for the "missing" ascenders
and descenders in a line which happens to contain only x-height
letters (eg acemnorsuvwxz). The one I created is slightly higher, to
force extra space between the rule and the cell below it.

///Peter

0 new messages