Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to work with a table of the form:

\begin{tabular}[]{l D{.}{.}{-1}}
  \multirow{2}{1in}{Here is a ton of text that is not going
  to fit in one single line in this 1 inch column.}         & 20.132  \\
  \vspace{5em}                                              & (9.218) \\
                                                            &         \\
  Next thing                                                & 1.311   \\
                                                            & (0.182)
\end{tabular}

I'm using multirow here to achieve the goal of having the numbers aligned with the top of the long label, with no lines separating the two numeric cells.

Essentially it should look like this:

Here is a ton of           20.132
text that is not           (9.218)
going to fit in one
single line in this
1 inch column.

Next thing                  1.311
                           (0.182)

The code above works, but notice how I've had to include \vspace{5em}. Without this, the ton of text overflows its allotted vbox onto the next thing. The problem is that visually inspecting the output and adding ems isn't ideal, especially as I need to automatically generate many tables that need this kind of wrapping/alignment. I'm using dcolumn, so I'm not sure I can change much with the numeric column.

So, finally, I'm looking for suggestions on how to properly provide space for the block of text inside \multirow, without manually inventing some vspace. Thanks for any info you can provide.

share|improve this question
    
So does the 2 in \multirow{2}{..}{<stuff>} refer to the fact that <stuff> pertains to the first two entries (20.132 and (9.218)) in the D column? Or does <stuff> only refer to 20.132? –  Werner Aug 19 '11 at 5:10
    
@Werner The multirow should span the cell in which it is defined, and one cell below it. –  user7334 Aug 19 '11 at 5:22
add comment

3 Answers

The D column specification forces the column into a fixed width. For that reason it is possible to contain elements in the numeric column in their own tabular. Also, even though \multirow{<#>}{<width>}{<stuff>} sets its depth based on the parameter <#>, the actual depth (in rows) is not obtained from typesetting <stuff> in a column of width <width>, as you have noted. Its depth is set by whatever is not contained in \multirow across the <#> rows. This limitation requires the forced/manual spacing which doesn't bode well for clean code. Instead of using the multirow package, nesting provides an appropriate solution:

\documentclass{article}
\usepackage{dcolumn}% http://ctan.org/pkg/dcolumn

\begin{document}

\begin{tabular}{p{1in} l}
  Here is a ton of text 
  that is not going
  to fit in one single line 
  in this 1 inch column.    & \begin{tabular}[t]{D{.}{.}{-1}}
                                20.132 \\
                                (9.218)
                              \end{tabular} \\ \\
  Next thing. Here is a 
  ton of text that is not
  going to fit in one 
  single line in this
  1 inch column.            & \begin{tabular}[t]{D{.}{.}{-1}}
                                 111.311 \\
                                (0.182)
                              \end{tabular}
\end{tabular}

\end{document}

Nested tabular with dcolumn

Note that the numeric (right-hand) column's tabular is set to align at the top [t] to line up with the first line in the first column.

share|improve this answer
    
Thanks, this is a much cleaner way of getting the right presentation. I didn't expect that nesting tabular environments could have any kind of good result. –  user7334 Aug 21 '11 at 0:48
add comment
\documentclass{article}   
\usepackage{dcolumn}   
\def\DTab#1{\multicolumn{1}{@{}c@{}}{\tabular[t]{D{.}{.}{-1}}#1\endtabular}}
\begin{document}

\begin{tabular}{ p{1in} D{.}{.}{-1}}
  Here is a ton of text that is not going
  to fit in one single line in this 1 inch column.          & \DTab{20.132\\(9.218)}\\
                                                            &         \\
  Next thing                                                & 1.311   \\
                                                            & (0.182)
\end{tabular}

\end{document} 

enter image description here

share|improve this answer
    
Now, nesting with \tabular, that's a good/clean/simple answer thanks! Everyone else is messing around with much more complicated answers. –  user31084 May 22 '13 at 14:36
add comment

I didn't use multirow, but I think the output is what you want:

\documentclass{article}
\begin{document}
\begin{tabular}[]{p{4.5cm}p{1cm}}
Here is a ton of text that is not going
to fit in one single line in this 1 inch column.    & 20.132   (9.218) \\\\

Next thing                                          & 1.311   (0.182)
\end{tabular}
\end{document}

The p{4.5cm}p{1cm} tells you the first column should be 4.5cm wide and the second column will be 1cm wide. By making the second column only 1cm wide, the numbers end up stacking like you wanted.

share|improve this answer
    
As the question was originally written, this works great, but I need to do dcolumn alignment on the numeric column. I updated my post to reflect this. –  user7334 Aug 19 '11 at 3:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.