I define a macro \mycmd
like this
\newcommand\mycmd[2]{{some complicated format #1}&{some complicated format #2}\\}
to simplify the input. So I can just write:
sometext
\begin{longtable}{cc}
\mycmd{contentA1}{contentA2}
\mycmd{contentB1}{contentB2}
\mycmd{contentC1}{contentC2}
...
But, at the end of the longtable, as
\mycmd{contentZ1}{contentZ2}
\end{longtable}
some text
there is a white space between longtable and text. How can I eliminate the space by just setting a command at the end of the last \mycmd
like
\mycmd{contentZ1}{contentZ2}\avalidmacro
\end{longtable}
some text
to let the table near to the text?
—Resupply MWE for comparison—
\setlength{\LTpre}{0pt}\setlength{\LTpost}{0pt}%
\begin{longtable}{cc}
sample table text&sample table text\\
\end{longtable}
main text main text main text main text
\begin{longtable}{cc}
sample table text&sample table text
\end{longtable}
main text main text main text main text
main text main text main text main text
—Edit for Yiannis—
\documentclass{article}
\usepackage{longtable,xcolor}
\def\fqdi{fqd}
\def\fqdv{\fqdi\ \fqdi\ \fqdi\ \fqdi\ \fqdi\ }
\begin{document}
\setlength{\LTpre}{0pt}\setlength{\LTpost}{0pt}%
\itshape
\fqdv\fqdv
\begin{longtable}{cc}
\color{red}\fqdv\fqdv&\color{red}\fqdv\fqdv\\
\end{longtable}
\fqdv\fqdv
\begin{longtable}{cc}
\color{red}\fqdv\fqdv&\color{red}\fqdv\fqdv
\end{longtable}
\fqdv\fqdv
\fqdv\fqdv
\begin{tabular}{cc}
\color{blue}\fqdv\fqdv&\color{blue}\fqdv\fqdv
\end{tabular}
\fqdv\fqdv
\end{document}
The red is the text in longtable, the blue is the text in tabular, black the main text.
- You will find a slightly space added to the first line's red and the second line's black.
- The red is not centered between lines, while the blue is.
Queation:
- eliminate the effect of
\\
; - make
longtable
's text same astabular
's text, centering between lines.
Best Answer
It is not your command, but rather the amount of glue allowed at the end of the table. See this minimal and adjust slightly the
LTpost
value.It is always better to fully provide a working minimal, as I have done here. Uncomment the
\hline
to see the space between the rows. Also it is better to use "semantic" commands, for example instead of\mycmd
rather use\addrow
.