Oh! Sorry I think this is an unreported bug in longtable
.
Longtable inserts a strut to keep a minimal separation between the text and any \hline
or the previous row.
It does this with the following code
\def\LT@startpbox#1{%
\bgroup
\let\@footnotetext\LT@p@ftntext
\setlength\hsize{#1}%
\@arrayparboxrestore
\vrule \@height \ht\@arstrutbox \@width \z@}
If you look at the equivalent code in the array
package, you find
\def\@startpbox#1{\bgroup
% \end{macrocode}
% The argument is the width of the box. This information has to be
% assigned to =\hsize=.
% Then we assain default values to several parameters used in a
% \textsf{parbox}.
% \changes{v2.3k}{1998/05/12}{Use \cs{setlength} to set \cs{hsize},
% so that the calc package can be applied here (pr/2793)}
% \begin{macrocode}
\setlength\hsize{#1}\@arrayparboxrestore
% \end{macrocode}
% Our main problem is to obtain the same distance between succeeding
% lines of the \textsf{parbox}.
% We have to remember that the distance between two \textsf{parboxes}
% should be defined by =\@arstrut=. That means that it can be
% greater than the distance in a \textsf{parbox}.
% Therefore it is not enough to set a =\@arstrut= at the
% beginning and at the end of the \textsf{parbox}. This would
% dimension the distance
% between first and second line and the distance between the two
% last lines of the \textsf{parbox} wrongly.
% To prevent this we set an invisible rule of height
% =\@arstrutbox=
% at the beginning of the \textsf{parbox}. This has no effect on the
% depth of the first line. At the end of the \textsf{parbox} we set
% analogously another invisible rule which only affects the depth
% of the last line. It is necessary to wait inserting this strut
% until the paragraph actually starts to allow for things like
% =\parindent= changes via =>{...}=.
% \changes{v2.1c}{1992/12/14}{Use `everypar to insert strut}
% \begin{macrocode}
\everypar{%
\vrule \@height \ht\@arstrutbox \@width \z@
\everypar{}}%
}
% \end{macrocode}
% \end{macro}
The important bit being the last few lines which delay adding the strut by using \everypar
.
It seems to me the same fix should have been applied to longtable
so only 20 years too late I suggest
\def\LT@startpbox#1{%
\bgroup
\color@begingroup% Omit line if package date older than 2014/10/28
\let\@footnotetext\LT@p@ftntext
\setlength\hsize{#1}%
\@arrayparboxrestore
\everypar{%
\vrule \@height \ht\@arstrutbox \@width \z@
\everypar{}}%
% \vrule \@height \ht\@arstrutbox \@width \z@
}
which then makes both your tables have the same vertical spacing.
If you do this could you change
\ProvidesPackage{longtable}
[2004/02/01 v4.11 Multi-page Table package (DPC)]
to
\ProvidesPackage{longtable}
[2004/02/01 v4.11 Multi-page Table package (DPC) + strut fix]
I suspect after all this time I can't change longtable
s default spacing, however I should add an option to fix it.
The following achieves what you're after (and is possible even without multirow
):
\documentclass{article}
\usepackage{array,longtable,multirow}% http://ctan.org/pkg/{array,longtable,multirow}
\begin{document}
\begin{longtable}{|>{\bfseries}l|>{\bfseries}l|*{4}{l|}}
\hline
\multicolumn{2}{|l|}{} & \textbf{QR Codes} & \textbf{PDF417} & \textbf{DataMatrix} & \textbf{Maxi Code} \\
\hline
\multirow{3}{*}{Datacapacity} & Numeric & 7.089 & 2.710 & 3.116 & 138 \\ \cline{2-6}
& Alphanumeric & 4.269 & 1.850 & 2.355 & 93 \\ \cline{2-6}
& Bytes & 2.953 & 1.018 & 1.556 & \\
\hline
\multicolumn{2}{|l|}{Pros} & Great capacity & Great capacity & Little size & High read \\
\multicolumn{2}{|l|}{} & High read & & & \\
\hline
\end{longtable}
\end{document}
I've avoided \parbox
and inserted an additional row. You could use a nested tabular
if you want lines broken inside the cell. For example,
\begin{tabular}[t]{@{}l@{}}
Great capacity \\
High read
\end{tabular}
The use of [t]
aligns the tabular
at the t
op, while @{}
removes any column padding, on both sides.
- For ease of use, the column specification of
*{4}{l|}
repeats l|
4 times.
- You could use
p
-columns, but then you need to specify the widths in such a way that the table fits within the text block (horizontally). Your code snippet already has 5 columns of width .18\textwidth
, and then a single column of width .1\textwidth
, totalling \textwidth
. However, there is still padding around each column (roughly 2\tabcolsep+\arrayrulewidth
).
Without more detail on the size of your text block (or page orientation), it's difficult discussing alternatives to your table.
Finally, table representations are sprinkled with fairy dust if you consider the booktabs
package. Moreover, there's little use in a longtable
when your table is not that long...
Best Answer
As already hinted in the very first comment, using
p
columns with an appropriate width is the solution to prevent manual line breaking.I don't know why you are nesting tabulars. You might be looking for
m
columns. I changed the table in its implementation quite a bit and adjusted the width by trial and error.