2

I'm using a tabular to create a listing that contains two items. I noticed, however, that the line spacing before the tabular differs from the spacing after regular text. In the case before the tabular, there is only too little line space when the line does not contain a character that drops below the writing line.

Is there a way to ensure that the line spaces are the same?

EDIT: Following the kind suggestion by David Carlisle, I removed all the \\ and thereby elimited the underful hboxes (\bigskip seems to be a proper way to insert the paragraph breaks I think?). But there is still inconsistent spacing between the tabular and the preceding line:

MWE2:

\documentclass[11pt]{memoir}

\begin{document} \noindent List 1 (works as wanted):

\noindent
ZZZZZZZZZZ

\noindent
ZZZZZZZZZZ\bigskip

\noindent 
List 2 -- too little line sPace above the tabular:

\noindent 
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l l}
    ZZZZZZZZZZ & ZZZZZZZZZZ \\
    ZZZZZZZZZZ & ZZZZZZZZZZ 
\end{tabular*}\bigskip

\noindent 
List 3 -- works as expected above the tabular:

\noindent 
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l l}
    ZZZZZZZZZZ & ZZZZZZZZZZ \\
    ZZZZZZZZZZ & ZZZZZZZZZZ 
\end{tabular*}

\end{document}

gives: enter image description here

cktai
  • 823
  • The problem is not tabular it is the misuse of \\ You get at least eight warnings Underfull \hbox (badness 10000) in paragraph at lines 4--8 10000 is the maximum level of badness warning about bad output, all of them are due to \\ – David Carlisle Feb 11 '21 at 13:37
  • https://tex.stackexchange.com/questions/334246/what-does-the-phrase-underfull-hbox-badness-10000-in-paragraph-actually-mea/334249#334249 – David Carlisle Feb 11 '21 at 13:39
  • I adjusted the MWE, but the problem above the tabular persists – cktai Feb 11 '21 at 14:25
  • use[t] option to the tabular to normalize the top spacing (normalizing top and bottom is a little harder – David Carlisle Feb 11 '21 at 14:32
  • you are adding bigskip in horizontal mode which works but adding it in vertical mode is safer but any real document should not have bigskip and noindent just specify globally that paragaraphs are not indented and are separated by vertical space. in memoir you can use \nonzeroparskip and \setlength\parindent{0pt} – David Carlisle Feb 11 '21 at 14:38
  • The reason why I use noindent and bigskip is because I need this formatting for only a single page in a larger document – cktai Feb 11 '21 at 14:57

2 Answers2

2

You can use [t] so the reference point of the tabular is on its first baseline and the baseline to baseline spacing above the table is naturally preserved.

enter image description here

\documentclass[11pt]{memoir}

\nonzeroparskip \setlength\parindent{0pt} \begin{document}

List 1 (works as wanted):


ZZZZZZZZZZ\\   
ZZZZZZZZZZ


List 2 -- too little line sPace above the tabular:


\begin{tabular*}{\textwidth}[t]{@{\extracolsep{\fill}}l l}
    ZZZZZZZZZZ & ZZZZZZZZZZ \\
    ZZZZZZZZZZ & ZZZZZZZZZZ 
\end{tabular*}


List 3 -- works as expected above the tabular:


\begin{tabular*}{\textwidth}[t]{@{\extracolsep{\fill}}l l}
    ZZZZZZZZZZ & ZZZZZZZZZZ \\
    ZZZZZZZZZZ & ZZZZZZZZZZ 
\end{tabular*}

\end{document}

David Carlisle
  • 757,742
2

We can emulate your problem at TeX primitive level (without LaTeX). You insert a multiline \vbox into lines and you want to keep \baseline grid. Your example looks like:

XXXX\par
ZZZZ\par % these two lines are in \baseline grid
\vbox{
 \hbox{first line}
 \hbox{second line}
}
YYYY

This keeps the baseline grid between second line and YYYY, but not between ZZZZ and first line because \vbox itself behaves as single line which is too hight: baseline goes throw the last box in the \vbox and all material above this last box is interpreted as the height of this single line.

D. Carlisle suggests to use \vtop instead \vbox in this case. This \vtop behaves as single line with baseline going throw the first box inside \vtop. Then baseline grid between ZZZZ and first line will be OK, but this grid is corrupted between second line and YYYY. This is due to the fact that all material under the first box in \vtop constructs the depth of the single line.

The solution is using \vtop and one trick with \prevdepth primitive register:

XXXX\par
ZZZZ\par % these two lines are in \baseline grid
\vtop{
   \hbox{first line}   % this keeps baseline grid because \vtop
   \hbox{second line}
   \par \expandafter
}\expandafter\prevdepth\the\prevdepth % this keeps baseline grid because \prevdepth

YYYY

wipet
  • 74,238
  • yes I was waiting to see if the OP needed to adjust the bottom spacing as well. If the table is set off with vertical space and you are not required to keep the following paragraph on a fixed grid layout, you can often avoid it (but +1, latex doesn't exactly help do that prevdepth trick but you know that:-) – David Carlisle Feb 11 '21 at 17:31
  • https://tex.stackexchange.com/a/583161/1090 :-) – David Carlisle Feb 12 '21 at 21:13