2

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} 

1 Answer 1

1

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

5
  • This does not seem to work any longer, sadly. Commented Sep 11, 2024 at 19:57
  • Got some success with \begin{tcblisting}{listing only, empty,left=0pt,right=0pt,top=0pt,bottom=0pt,boxsep=0pt,baseline=2mm} instead of \begin{lstlisting}, somehow… Commented Sep 11, 2024 at 20:07
  • @Michaël My original code still works for me, using TeXlive 2023 Commented Sep 11, 2024 at 23:14
  • 1
    That's what I get: i.imgur.com/TkH0afj.png Notice the MATCH line being slightly too low. That's with TeXlive 2024.2. On Overleaf, the jump seems to be between TeXlive 2022 and 2023. Commented Sep 15, 2024 at 16:50
  • @Michaël Actually, I now see what you mean...TeXlive 2023 produces the same vertically shifted result. Commented Sep 15, 2024 at 21:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.