# synttree in tabular: vertical alignment of other columns

synttree is a package that allows you do define tree graphs in an easy way. Now I'm trying to put such a tree in a table cell like so:

\begin{tabular}{lp{3cm}}
...
My left column &
\synttree[A [B] [C]]\\
...
\end{tabular}


Unfortunately, the use of \synttree in the right column influences the vertical alignment of the left column. Normally, "My left column" would appear at the top of the cell, but in my example it is written at the bottom of the cell:

+----------------+----------+
| My left column |     A    |
|                |    / \   |
|                |   B   C  |
+----------------+----------+


(expected)

+----------------+----------+
|                |     A    |
|                |    / \   |
| My left column |   B   C  |
+----------------+----------+


(actual)

How can I make the text in the left column go to the top of the cell?

-

A quick fix:

\documentclass{article}
\usepackage{synttree}
\usepackage{array}

\begin{document}
\begin{tabular}{l>{\vspace{-.5\baselineskip}}p{3cm}}
My left column & \synttree[A [B] [C]]\\\hline
My left column & \synttree[A [B] [C]]\\
\end{tabular}
\end{document}


Here is the precise solution. We compute the extra height of letter "A" in the root of tree:

\documentclass{article}
\usepackage{synttree}
\usepackage{array}
\makeatletter
\settoheight\@tempdima{A}
\newcolumntype{P}[1]{>{\vspace{-\@tempdima}}p{#1}}
\makeatother
\begin{document}
\begin{tabular}{lP{3cm}}
\hline
My left column & \synttree[A [B] [C]]\\\hline
My left column & My right column\\
\hline
\end{tabular}
\end{document}


Another choice is to use qtree package instead. qtree produce better output of syntax trees.

\documentclass{article}
\usepackage{qtree}
\begin{document}
\qtreecenterfalse % do not center
\begin{tabular}{lp{9cm}}
My left column & \Tree[.A [.B ] [.C ] ] \\
\end{tabular}
\end{document}


-
@Leo, thanks for your answer, it works fine for my original question. However, if my second column is defined as 'c' instead of 'p{3cm}' your solution fails. How can I adapt it for the centered case? –  Thomas Feb 8 '11 at 14:35
Use \newcolumntype{C}[1]{>{\centering\arraybackslash\vspace{-\@tempdima}}p{#1}} for centered columns, where C works like P columntype, say, use \begin{tabular}{lC{3cm}}. –  Leo Liu Feb 8 '11 at 16:40
@Thomas: See also tex.ac.uk/cgi-bin/texfaq2html?label=tabcellalign –  Leo Liu Feb 8 '11 at 16:43
@Leo, that's awesome - but now I have to specify a fixed width for the column, right? I don't think that's going to be a problem, though. –  Thomas Feb 8 '11 at 17:01
@Thomas: Yes, you must specify a fixed width, if you use this solution. There are other solutions, but may be more awesome. Or try to use qtree instead? –  Leo Liu Feb 8 '11 at 17:05

use it this way:

\documentclass{article}
\usepackage{synttree}
\usepackage{array}
\newcolumntype{P}[1]{>{\vspace{0pt}}p{#1}}

\begin{document}
\begin{tabular}{P{3cm}P{3cm}}\hline
My left column & \synttree[A [B] [C]]\\\hline
\end{tabular}

\end{document}


-
It's good, except that there is extra space. –  Leo Liu Feb 7 '11 at 14:57
The \newcolumntype command doesn't need to take an argument: \newcolumntype{P}{>{\vspace{0pt}}p} works just as well. Is there a reason not to do it that way? –  Alan Munn Feb 7 '11 at 15:23
@Alan: I think @Herber's definition is more convenience, since we often don't know how \newcolumnntype works. –  Leo Liu Feb 7 '11 at 15:38
@Leo I guess I've always thought of new columns as inheriting the properties of the types they are built on, and explicitly adding the argument doesn't seem to add much. –  Alan Munn Feb 7 '11 at 15:41
@Leo: replace 0pt with -1ex –  Herbert Feb 7 '11 at 15:45