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 want a table whose first column is aligned top, second column is aligned middle, and third column is aligned bottom; like this:

I wrote the following code:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{array}

\begin{document}

\begin{tabular}{| p{1cm} | m{1cm} | b{1cm} |}
    \hline
    x &
    A long text comes here &
    x \\
    \hline
\end{tabular}

\end{document}

Yet, to my surprise, the outcome was "all columns aligned middle," as follows:

What did I do wrong?

share|improve this question
1  
After doing some experimenting, I found out that the long text seems to dominate. Everything else is getting aligned the way that it's aligned. Maybe you need to try adding in the multirow environment? –  philosodad Dec 1 '10 at 21:09
    
@philosodad: Yeah, I reached to the same conclusion: the long text dominates. I'll examine the multirow, but I wanted to know if the domination is a bug or something? –  Sadeq Dousti Dec 1 '10 at 21:51
    
You get the same behavior with \parbox[t]{1cm}{x}\parbox{1cm}{A long text comes here}\parbox[b]{1cm}{x}, and since p m and b correspond to to these kinds of parboxes, array does work the way the manual says. I'm just not sure what the bet way of dealing with this issue is. –  frabjous Dec 1 '10 at 22:02
    
@frabjous: The question is, why \parbox offers such behavior? I expect p, m, and b to align vertically at top, middle, and bottom, respectively. –  Sadeq Dousti Dec 1 '10 at 22:16
2  
With parbox, it's not surprising. There's the active line of text. The differences between p m and b only matter when the stuff in the parbox is larger than one line. The "X"'s are just "on the line", and so the way they hang past the line don't matter. The only parbox that extends past the line is the middle one, and it gets centered, because it's m. Try making each "X" two lines of text and you'll see what p and b do, e.g., \parbox[t]{1cm}{some words}\parbox{1cm}{A long text comes here}\parbox[b]{1cm}{some words} –  frabjous Dec 1 '10 at 23:21

3 Answers 3

up vote 6 down vote accepted

You could use optional arguments of \parbox for vertical alignment and vertical size. Here's a small demonstration example, I just quickly estimated the height. Inserting \vspace{0pt} is a trick for changing the base line for the alignment. Without it, we would get a lot of additional whitespace.

\documentclass{article}
\newcommand*{\tabbox}[2][t]{%
    \vspace{0pt}\parbox[#1][3.7\baselineskip]{1cm}{\strut#2\strut}}
\begin{document}
\begin{tabular}{| p{1cm} | p{1cm} | p{1cm} |}
    \hline
    \tabbox{x} &
    \tabbox{A long text comes here} &
    \tabbox[b]{x} \\
    \hline
\end{tabular}
\end{document}

Output:

alt text

share|improve this answer

The thing with the array package is you cannot use p{...}, m{...} and b{...} in the same table. m{...} will usually override the other two if they are present. You might just want to manually insert your vertical space or do your alignment within the multirow environment.

share|improve this answer

This isn't an answer per se, but rather an observation from, what I gather, a "lower" level:

\parindent=0pt
\baselineskip=0pt
\raggedright
\halign to .2\hsize{
  \vbox to 20pt{\hsize=.05\hsize#\vfil}&% cmr10*2=20
  \vbox to 20pt{\hsize=.10\hsize#\vfil}&
  \vtop to 20pt{\hsize=.05\hsize#\vfil}\cr
  \hfill x&long text here&x\cr
  \centerline{wtf}&is happening here&huh?\cr
}\hfill
\bye

enter image description here

Notice how the first 'x' is higher than the following vbox, and the last column content is lower than the middle column content, even though the explicit height definitions. Also I've no clue where does the white-space between the rows come from.

I, too, sure would like to know what is happening.

share|improve this answer
    
Your image doesn't work anymore. Could you reupload it? –  doncherry Jan 15 '12 at 21:22
    
@doncherry: sure, I did that. Thanks for the heads-up! These missing image-issues keep coming up now and again, I wonder why. –  morbusg Jan 15 '12 at 22:19
    
It looks like you're another case of meta.tex.stackexchange.com/questions/1440/…. Well, some more reuploading for me to do :). Just make sure that whenever you upload pictures, you do so through the official interface, i.e. by clicking on the respective button or pushing Ctrl+G. (I first thought your case was different because I falsely removed the i., but removing the stack. (and reuploading them) brings back your images. –  doncherry Jan 15 '12 at 22:31
    
@doncherry: oh, right, I think at the time when I originally posted this, uh, "answer", there wasn't an official interface yet in place. –  morbusg Jan 15 '12 at 22:37
    
All fixed. The problem only appear in your older posts, so that's probably the explanation. –  doncherry Jan 17 '12 at 9:35

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.