# Reduce line height in p type table cells

I need to set a big table and want to compress it in a way that it fits on one page. The table contains a column of type p with text breaking over multiple lines. Now I want to reduce the overall line spacing. Usually, I'm using a \renewcommand{\arraystretch}{0.9} for that, but that does not seem to work for p columns. See the following example (I set the spacing to 0.5 to make my goal more clear):

\documentclass[ngerman]{scrbook}
\begin{document}
{
\renewcommand{\arraystretch}{0.5} % this reduces the vertical spacing between rows
\begin{table}
\centering
\begin{tabular}{l p{5cm}}
\hline
row one &
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog. \\
row two \\
row three \\
\hline
\end{tabular}
\end{table}
}
\end{document}


This produces the following result:

Beside the spacing between the rows (green arrow), I would like to reduce the line spacing in between the "the quick brown fox" lines as well (red arrow). Any hints strongly appreciated.

-
You can use & \baselineskip=10pt for example, to change it locally. I guess that it is not the best solution, but it works. –  Sigur May 24 at 16:38
Thank you, I defined a command for that, which makes it a bit less repetitive. Still, if anybody has a global solution (wrt table) that would be great. –  qqilihq May 24 at 16:59

## 4 Answers

The result is disastrous, in my opinion. But here it is, without extra packages and extra commands.

\documentclass[ngerman]{scrbook}
\begin{document}

\begin{table}
\renewcommand{\arraystretch}{0.5} % this reduces the vertical spacing between rows
\linespread{0.5}\selectfont\centering
\begin{tabular}{l p{5cm}}
\hline
row one &
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog. \\
row two \\
row three \\
\hline
\end{tabular}
\end{table}
\end{document}


Note that the setting to \baselinestretch (made by \linespread) and to \arraystretch are local to the table environment; you don't need to have them outside the environment which, on the other hand, makes a group so that the previous values will be reverted at \end{table}.

-
the "paragraphed" material would really look better ragged right. –  barbara beeton May 24 at 20:44
@barbarabeeton I think there's no mending that can improve that disaster. –  egreg May 24 at 20:54
  \usepackage{array}


Then

\newcolumntype{P}[1]{>{\small}{p{#1}}


or

\newcolumntype{P}[1]{>{\linespread{.9}}{p{#1}}


If you think you can get away with squeezing the linespacing while keeping the text size.

Then use P{..} instead of p{..}

-
Both of them do not work for me unfortunately, I'm getting the error Paragraph ended before \newcol@ was complete. [] while building. –  qqilihq May 25 at 7:36
@qqilihq Then you have a missing } –  David Carlisle May 25 at 8:09

It enough to use the \setstretch command from the setspace package. As the row could be undistinguishable, for better readability I introduced a minimal spacing between rows (expressed in ex units, so that it varies with the fontsize) through the cellspace package. I used booktabs in order to have a better vertical spacing for the horizontal lines. Finally, you can play with the fontsize in the table. I give an example with \footnotesize:

\documentclass[ngerman]{scrbook}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{cellspace}
\setlength\cellspacetoplimit{0.8ex}

\begin{document}

Text text text text text text text text text text text text text text text text text text text text text text text text tex text.

\begin{table}[!htbp]
\centering\footnotesize\setstretch{0.5}
\begin{tabular}{Sl p{5cm}}
\toprule
row one &
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog. \\
row two &
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog.\\
row three &
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog.\\
\bottomrule
\end{tabular}
\end{table}

\end{document}


-

Note: in my first attempt to give an answer -- since unfortunately I'm still not familiar with SE -- I made a terrible mess from which I was (in this moment) unable to (re)edit my answer and correct in last second observed error in it. Sorry for this. Now I try to correct this and all puts on right place.

Well, meanwhile you got good answers from others, so I added main just to eliminate my previous (locked) mess.

Answer: If you explicitly (again) declare font family in the table environment, for examaple with \rmfamily, than work the following MWE:

\documentclass{article}
\usepackage[active,floats,tightpage]{preview}   %just for showing only table
\begin{document}
\begin{table}[h!]\centering
\linespread{0.8}                    %   this decrease the vertical spacing between lines
\rmfamily                           %   without this, \linespread doesn't give expected effect
%   to be honest, I do not know, why this is necessary
\begin{tabular}{l p{5cm}}
\hline
row one     &
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog.
the quick brown fox jumps over the lazy dog. \\
row two     &   \\
row three   &   \\
\hline
\end{tabular}
\end{table}
\end{document}


I tested above MWE with article package since I newer use scrbook. I believe/hope, that it also should work with scrbook.

The declaration of \rmfamiliy (or for example \sffamily, which I usually use in my tables) inside table environment make \linespread{<reduction factor>} active in all table cells. Why it is necessary, I do not know.

-