1

I can't get listings to vertically align at the top of table cells. Here's an example.

\documentclass{article}
\usepackage{hyperref}
\usepackage{listings}

\begin{document}
\begin{tabular}{ll}
$q_{1}:$ & \begin{lstlisting}[language=SQL, boxpos=t]
SELECT *
FROM mytable
\end{lstlisting}
\end{tabular}
\end{document}

I'm using boxpos=t. If I comment out \usepackage{hyperref} then I get the alignment I want (text and listing top-aligned). But otherwise it produces the following output:

bad vertical alignment in table

How can I achieve top-aligned cells, while using hyperref?

  • Probably unrelated to the question, but hyperref should generally (with a few exceptions) be the last package in the preamble. – leandriis Oct 19 '19 at 12:07
1

Try the following:

\documentclass{article}
\usepackage{listings}
\usepackage{hyperref}

\begin{document}
\begin{tabular}{lp{0.5\linewidth}}
$q_{1}:$    &   \vspace{-\baselineskip}
\begin{lstlisting}[language=SQL, boxpos=t]
SELECT *
FROM mytable
\end{lstlisting}
\end{tabular}
\end{document}

enter image description here

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.