# how to remove extra line break inside longtable after listing?

I have one column specification set as p{4in} in a longtable. I keep getting an extra empty line in this column for some reason.

I use listing inside the column, since I need to break the listing inside the column. Everything works ok, except there is this extra blank line.

MWE

\documentclass[11pt]{article}

\usepackage{listings}
\lstset{
breaklines=true,
basicstyle=\ttfamily\small
}
\usepackage{longtable}
\usepackage{hyperref}
\setlength\parindent{0pt}

\begin{document}

\begin{longtable}[c]{|l|p{4in}|}\hline
\#&ODE and type of ODE\\\hline
\hyperlink{subsection_1}{ODE 1}&$y'(x)=a f(x)$
\begin{lstlisting}
\end{lstlisting}
\\\hline
\hyperlink{subsection_2}{ODE 2}&$y'(x)=y(x)+x+\sin (x)$
\begin{lstlisting}
[[_linear, class A]]
\end{lstlisting}
\\\hline
\end{longtable}

\end{document}


Here is the PDF

I need to have the math equation on one line, and below it a listing. But I do not need that extra empty line that shows below the listing.

I tried breaklines=false for the listing options, but still get an empty line below the listing. If I remove the whole listing part, then the extra empty line goes away. So it seems a side effect of having the listing there?

tex live 2016.

• @cfr I just tried it. It seemed to increase the spacing :( still empty line below the listing. Tried different values \\[-10\baselineskip]\hline does not seem to have any effect. still empty line below listing. Thanks. – Nasser Dec 28 '16 at 2:41
• if you not use array package than works \end{lstlisting}\vspace{-1.2\baselineskip}\\ \hline. – Zarko Dec 28 '16 at 2:49
• @Zarko great! That worked. Please feel free to post this as answer and will be happy to accept it. – Nasser Dec 28 '16 at 2:56

It seems that use of lstlisting in longtable is not straightforward ...

If you not use array package in document, than a rude solution is add \vspace{-1.2\baselineskip} \\\hline after the end{lstlisting}:

\documentclass[11pt]{article}
\usepackage{listings}
\lstset{
breaklines=true,
basicstyle=\ttfamily\small
}
\usepackage{longtable}
\usepackage{hyperref}
\setlength\parindent{0pt}

\begin{document}
\begin{longtable}{|l|p{4in}|}\hline
\#                              &   ODE and type of ODE \\  \hline
\hyperlink{subsection_1}{ODE 1} &   $y'(x)=a f(x)$
\begin{lstlisting}
\hyperlink{subsection_2}{ODE 2}&$y'(x)=y(x)+x+\sin (x)$
[_linear, class A]