2

Moin,

I want the rowspacing behavior to be default. So this:

\usepackage{longtable}

% ... MAGIC ... %

\begin{longtable}{ccc}
  entry1 & entry2 & entry3 \tabularnewline
  entry4 & entry5 & entry6 \\
  entry7 & entry8 & entry9 \newline
                    foobar
\end{longtable}

should produce the same output as this:

\usepackage{longtable}

% ... MAGIC ... %

\newlength\myRowSpacing
\myRowSpacing1ex

% ... MAGIC ... %

\begin{longtable}{ccc}
  entry1 & entry2 & entry3 \tabularnewline[\myRowSpacing]
  entry4 & entry5 & entry6 \\[\myRowSpacing]
  entry7 & entry8 & entry9 \newline
                    foobar
\end{longtable}

Note how it should not apply to newlines (so multi-line cells have default linespacing).

What I tried:

\usepackage{longtable}
\usepackage{setspace}
\usepackage{etoolbox}
\AtBeginEnvironment{longtable}{\doublespacing}

% ... MAGIC ... %

\begin{longtable}{ccc}
  entry1 & entry2 & entry3 \tabularnewline
  entry4 & entry5 & entry6 \\
  entry7 & entry8 & entry9 \newline
                    foobar
\end{longtable}

This produces something I like. Might be even better than the fixed spacing solution, if I figure out a nice factor... Except that it also applies to newlines - and I haven't succeeded in redefining newlines (yet).

So, what hack have I missed?

Regards, LDericher

David Carlisle
  • 757,742
LDericher
  • 185

2 Answers2

3

longtable obeys \arraystretch or (with array package) \extrarowheight so if you want a spaced out longtable define

 \renewcommand\arraystretch{2}
 \begin{longtable}{...}
David Carlisle
  • 757,742
  • This is exactly what google and a bunch more search machines refused to tell me! Are there any conflicts/problems with redefining arraystretch? – LDericher May 19 '14 at 19:43
  • @LDericher I don't mention it in the longtable documentation either, I just looked:-) It is supposed to be implicit in the fact that longtables work like standard tabular. – David Carlisle May 19 '14 at 19:46
  • I didn't know that property at all, yet. So no implicitness for me, I guess ;) – LDericher May 19 '14 at 20:12
  • 1
    @LDericher as for redefining \arraystretch: that's its only purpose so you can define it to stretch arrays, the only compatibility issue is that it applies to any nested tabular environments so if you have a longtable cell that contains a tabular and you don't want that to stretch then you will need ...&\renewcommand\arraystretch{1}\begin{tabular}... to locally put it back inside the cell. – David Carlisle May 19 '14 at 20:16
0

\newline has to be used in paragraph cells p. Also see How to add a forced line break inside a table cell for that topic.

Using \doublespacing will also affect such paragraphs inside your table. So you better declare an own command \newcommand*\nl{\\[3ex]} and use it at the end of the line.

Maybe your try some other packages, like tabu which easily allows horizontal aligning in its tables. For vertical aligning maybe see my own question Tables: vertical alignment of cell

PS. next time consider to put all of your 3 code examples in one compilable MWE.

musicman
  • 3,559
  • I actually used p cells, but I built my examples to fit, when I missed that aspect. And I also forgot to mention I don't really like using an own command for that purpose if possible. – LDericher May 19 '14 at 19:40