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}

1 Answer 1

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .