# Ignore whitespaces inside of a table

I would like to eliminate blank parts of a table. Here is my LaTeX snippet:

\documentclass[english,a4paper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}
\usepackage{changepage}

\begin{document}

\clearpage
\begin{table}[ht]
\begin{tabular}{|p{.6\textwidth}|p{.75\textwidth}|}
\hline
{\begin{lstlisting}[basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,language={Java},
numbersep=8pt,numbers=left,xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords={class,run}]
void run(Dummy x) {
out.println("Hello world")
}
}
class X ext ProxifiedObject {
void main(X x) {
}
}
\end{lstlisting}}
&
{\begin{lstlisting}[
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,
language={Java},
numbersep=8pt,
numbers=left,
xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords ={class,run}
]
void run(Dummy x) {
out.println("Hello world")
}
}
class X ext ProxifiedObject {
void main(X x) {
}
}
\end{lstlisting}}
\\
\hline
\end{tabular}
\caption{\label{fig:text}text experiment ent experiment experiment}
\end{table}
\end{document}


-
You can reduce the column size in {|p{.6\textwidth}|p{.75\textwidth}|} Is that what you want? –  Harish Kumar Mar 31 '14 at 23:36
The table only has so much white space as you specified the second column to be very wide |p{.6\textwidth}|p{.75\textwidth}|} –  David Carlisle Mar 31 '14 at 23:36
what if I have a large code snippet and need to set textwidth as .8? –  Hakan Mar 31 '14 at 23:50
If your text is wider, how can you hope to miss out the space at the end of the (shorter) lines? –  Joseph Wright Apr 1 '14 at 10:37

In order to refine the whitespace of the table, I have found a quick way to do that. First inside of the table there are two listings so that if the following commands aboveskip,belowskip are used in these listings' properties, below and above empty spaces are gone.

\documentclass[english,a4paper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}
\usepackage{changepage}

\begin{document}

\clearpage
\begin{table}[ht]
\begin{tabular}{|p{.6\textwidth}|p{.75\textwidth}|}
\hline
{\begin{lstlisting}[basicstyle={\scriptsize\ttfamily},aboveskip=-8pt,belowskip=-10pt,
identifierstyle={\color{black}},
tabsize=2,language={Java},
numbersep=8pt,numbers=left,xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords={class,run}]
void run(Dummy x) {
out.println("Hello world")
}
}
class X ext ProxifiedObject {
void main(X x) {
}
}
\end{lstlisting}}
&
{\begin{lstlisting}[
basicstyle={\scriptsize\ttfamily},aboveskip=-8pt,belowskip=-10pt,
identifierstyle={\color{black}},
tabsize=2,
language={Java},
numbersep=8pt,
numbers=left,
xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords ={class,run}
]
void run(Dummy x) {
out.println("Hello world")
}
}
class X ext ProxifiedObject {
void main(X x) {
}
}
\end{lstlisting}}
\\
\hline
\end{tabular}