4

I am trying to display to codes side-by-side, using this:

\begin{center} \begin{tabular}{c|c}  \begin{lstlisting}
while (x > 0) do
  x++; \end{lstlisting} & \begin{lstlisting}
x = 0; \end{lstlisting}  \end{tabular}\end{center}

Here is what is displayed after compilation: latex code lstlisting

The problem is, the vertical line of the tabular goes too far. I have tried to play with the lstlisting parameters belowskip and aboveskip, and tried to use minipages too, but nothing seems to work properly.

My second problem is that using the code above, the second code ("x = 0;") is not aligned with the while. EDIT : the second issue is solved using minipages, thanks to cfr

Do you know how to solve this ?

vonbrand
  • 5,473
waffle
  • 57
  • 1
    Use minipages or \parboxes with [t] alignment for the second problem. – cfr Jul 30 '15 at 01:51
  • You might be interested in this answer: http://tex.stackexchange.com/questions/210284/how-to-write-pseudocode-similar-to-code-presented-in-beautiful-code-by-j-r-h/217644#217644 – Henri Menke Jul 30 '15 at 06:32
  • Thanks Henri, I have a working solution using minipages and vrule. But I hoped I could use a tabular and no vrule to do this (this would be cleaner for me) – waffle Jul 30 '15 at 10:16

1 Answers1

2

enter image description here

We got the above image with the assistance of array package, you can change the width of columns as you like

% \usepackage{array}  


\begin{center} 
\begin{tabular}{p{3.9cm}|p{3.9cm}} 
 \begin{lstlisting}
while (x > 0) do
  x++; \end{lstlisting} &
   \begin{lstlisting}
x = 0; \end{lstlisting}  
\end{tabular}
\end{center} 
Salim Bou
  • 17,021
  • 2
  • 31
  • 76
  • Thank you for your answer but this is not what I was searching for. I am not trying to change the width of columns, but the height of the vertical line. – waffle Jul 30 '15 at 11:28
  • Try to reduce \arraystretch , example \renewcommand{\arraystretch}{0.2}. – Salim Bou Jul 30 '15 at 11:47