# How to embed lstlisting in table without much space

I want to embed code in table like the below photo.

Firstly, I tried code 1.

\begin{tabular}{p{8cm}}
\hline
\begin{lstlisting}
code here ......
\end{lstlisting}
\\ \hline
\begin{lstlisting}
code here ......
\end{lstlisting}
\\ \hline
\end{tabular}

However, there is too much space between hline and code.

Then, I tried answer in Remove top space from lstlisting inside tabular.

The space became less than first step. However, there is still much space.

If I want the effect just like picture above, how can I do?

Great thanks!!

You have options aboveskip and belowskip. If we set these values to zero, there is still a small space. We can get rid of it by setting negative values.

\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{tabular}{p{8cm}}
\hline
\begin{lstlisting}[aboveskip=-8pt,belowskip=-12pt]
code here ......
\end{lstlisting}
\\ \hline
\begin{lstlisting}[aboveskip=-8pt,belowskip=-12pt]
code here ......
\end{lstlisting}
\\ \hline
\end{tabular}
\end{document}

• Yes, you are right. I found the solution that is similar to yours. Great thanks~ – Young Apr 25 '19 at 1:37