1

I have the following problem.

lstlisting seems to add an extra space before and after the code.

Is there a way to remove it ?

I would like to remove the blank spaces before and after the code : "MATCH (n... "

enter image description here

    \lstset{language=C,
            basicstyle=\small,
            breaklines=true,
            aboveskip=0pt,belowskip=0pt}

    \begin {table}[!h] 
    \noindent
    \begin{tabular}{|c || p{14 cm}|}
    \hline
    \bf Plateforme  & \bf Code \\
    \hline                                        
    \hline      
    Neo4J & 
    \begin{lstlisting}
    MATCH (n {name: 1}) return n
    \end{lstlisting}
    \\ \hline     
    Titan & 
    Code B
    \\ 
    \hline                                                                                                                                          
    \end{tabular} 
    \end {table}
0

EDITED. I can't explain why it works, but it seems to. I put the listing into \box0, and that eliminated the top blank line. Placing an empty \mbox before the \box0 takes care of the line below (alternately, \leavevmode), for some reason that gives the appearance of still being in vertical mode.

I have verified that it works also for listing more than a line long.

To summarize the listing tabular entry:

\setbox0=\hbox{\begin{lstlisting}
MATCH (n {name: 1}) return n
\end{lstlisting}}\mbox{}\box0

Here is the MWE.

\documentclass[12pt]{article}

\usepackage{listings}

\begin{document}

\lstset{language=C,
            basicstyle=\small,
            breaklines=true,
            aboveskip=0pt,belowskip=0pt}

\begin {table}[!h] 
\noindent
\begin{tabular}{|c || p{14 cm}|}
\hline
\bf Plateforme  & \bf Code \\
\hline                                        
\hline      
Neo4J & 
\setbox0=\hbox{\begin{lstlisting}
MATCH (n {name: 1}) return n
\end{lstlisting}}\mbox{}\box0
\\ \hline     
Titan & 
Code B
\\ 
\hline                                                                                                                                          
\end{tabular} 
\end {table}
\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.