A: 

What if you use \lstinline for each cell, e.g. \lstinline!A!?

Bastien Léonard
Thx for you answers.The table vs tabular thing is now cleared up :)Unfortunately i don't see how \lstinline can help me.In the simplest case my table has a single row and 2 columns containing preformatted text using \begin...end{lstlisting} which is multiple lines long.But the shorter query is always vertically aligned in the middle of the longer one.For example if the text were 2 sql queries i would like their "select" parts starting on the same line instead of having the shorter select to start somewhere in the middle of the cell.
raven_arkadon
A: 

\usepackage{array} in your preamble.

then:

change this line: \begin{tabular}{|l|l|l|}

to this: \begin{tabular}{|m{width of cell}|m{width of cell} |m{width of cell}|}

the array package provides an extension to latex's tabular env. that will allow for the specification of the alignment of the text inside the cell. see the array package documentatio for more info.

Mica
This doesn't work for me. Reading the documentation for the `array` package, I can find a way to align everything along the **bottom**, but not the top (using `b{width}` instead of your `m{width}` ... using `t{width}` doesn't work). Also, you have to figure out the width of the columns manually, which is a pain.
Anton Geraschenko
reading the question again, it sounds like it might be the lstlisting package that is messing up the alignment... can you try a simple \vspace{-2in} or whatever length you need to see if it will pull that text to proper alignment?
Mica
Turns out that there is a way to get top alignment: use `p{width}` (`m{width}` gives center alignment and `b{width}` gives bottom alignment). But this still has the drawback that you have to input the width by hand. At least you can use widths like "`.3\linewidth`". Another drawback is that these commands add a lot over vertical padding (about an extra line on the top and bottom).
Anton Geraschenko
+1  A: 

It's a bit hacky, but you can use the escapechar keyword and just add extra lines so that they have the same length.

\begin{table}
\begin{tabular}{|l|l|} 
\hline
Head1 & Head2 \\ \hline
\begin{lstlisting}[escapechar=\%]
A
B

%%
\end{lstlisting}
&
\begin{lstlisting}
A
B 
C
D
\end{lstlisting}
\\ \hline
\end{tabular}
\end{table}

Edit: You only need to use the escape character for the last line (the above example has been modified to reflect this). Alternatively, if you don't mind an extra vertical padding and having to figure out the column widths by hand, you can solve this problem using the array package (as suggested by Mica) and replacing \begin{tabular}{|l|l|} with \begin{tabular}{|p{width}|p{width}|}. You might make width something like .5\linewidth.

Anton Geraschenko
Thank you, for the moment this solution does the trick for me.Would be nice if there was a solution without the line-counting hack though :)
raven_arkadon
A: 

\lstset{boxpos=t}