Skip to main content
added 171 characters in body
Source Link
Steven B. Segletes
  • 244.5k
  • 13
  • 346
  • 633

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. But

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}}\relax\mbox\mbox{}\box0 \\ \hline Titan & Code B \\ \hline \end{tabular} \end {table} \end{document} 

enter image description here

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, for some reason. But it works also for listing more than a line long.

\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}}\relax\mbox{}\box0 \\ \hline Titan & Code B \\ \hline \end{tabular} \end {table} \end{document} 

enter image description here

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

Source Link
Steven B. Segletes
  • 244.5k
  • 13
  • 346
  • 633

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, for some reason. But it works also for listing more than a line long.

\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}}\relax\mbox{}\box0 \\ \hline Titan & Code B \\ \hline \end{tabular} \end {table} \end{document} 

enter image description here