3

I have the following code where $q_1$ aligns in the middle. I would like to align it with the top line (SELECT). Is there a way to do that?

\documentclass{article}
\usepackage{listings}

\lstset{language=SQL}

\begin{document}
\begin{tabular}{ll}
$q_{1}:$ & \begin{lstlisting}
SELECT EMP.ENAME
FROM   EMP NATURAL JOIN ASG NATURAL JOIN PROJ
WHERE  PNAME="CAD/CAM"
\end{lstlisting}
\end{tabular}
\end{document}
4

With the boxpos=t option you can achieve the desired alignment:

enter image description here

\documentclass{article}
\usepackage{listings}

\lstset{language=SQL}

\begin{document}
\begin{tabular}{ll}
$q_{1}:$ & \begin{lstlisting}[boxpos=t]
SELECT EMP.ENAME
FROM   EMP NATURAL JOIN ASG NATURAL JOIN PROJ
WHERE  PNAME="CAD/CAM"
\end{lstlisting}
\end{tabular}
\end{document}

From the listings documentation:

boxpos=〈b|c|t〉: Sometimes the listingspackage puts a \hbox around a listing— or it couldn’t be printed or even processed correctly. The key determines the vertical alignment to the surrounding material: bottom baseline, centered or topbaseline. [...]

The default alignment is, as you observed c.

  • Beautiful. Many thanks. – ozsu Mar 8 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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