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