# How to eliminate the \\ at the end of a longtable

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:

1. eliminate the effect of \\;
2. make longtable's text same as tabular's text, centering between lines.
-
\setlength{\LTpost}{-15pt} or to suit –  Yiannis Lazarides Oct 24 '11 at 3:41
@Caramdir Edited. –  was long Oct 24 '11 at 3:55
@Yiannis Edited. –  was long Oct 24 '11 at 3:55

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.

\documentclass{article}
\usepackage{lipsum,longtable}
\newcommand\addrow[2]{{some complicated format #1}&{some complicated format #2}\\}
\setlength{\LTpre}{0pt}\setlength{\LTpost}{-1pt}%
\begin{document}
\lipsum[3]
\begin{longtable}{cc}
%\hline
%\hline
\end{longtable}
\lipsum[1]
\end{document}


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.

-
I have edited the origin post. Could you read it again? I wish there is a clever way instead of just directly decrease the \LTpost. –  was long Oct 25 '11 at 1:50

longtable wasn't really expecting to have to stitch tightly into the vertical list like this normally it's offset by some space or starts a new page. It could try harder, but currently you can correct for the depth of the previous paragraph (like most tabular longtable uses struts so its height and depth are known in reasonable cases.

I extended the test file with some digits at the start of the lines to make it easier to see which line is which in the \showoutput log. Also added a picture mode making a line every 12pt to show the intended baseline spacing.

\documentclass{article}
\usepackage{longtable,xcolor}
\def\fqdi{fqd}
\def\fqdv{\fqdi\ \fqdi\ \fqdi\ \fqdi\ \fqdi\ }
\setlength\parindent{0pt}
\setlength\parskip{0pt}
\showoutput
\begin{document}
\setlength{\LTpre}{0pt}\setlength{\LTpost}{0pt}%
\itshape

0\begin{picture}(0,0)
\multiput(9,0)(0,-12){10}{\line(-1,0){15}}
\end{picture}

1\fqdv\fqdv

\vskip-\prevdepth\vskip\dp\strutbox

\begin{longtable}{cc}
\color{red}2\fqdv\fqdv&\color{red}\fqdv\fqdv\\
\end{longtable}

\vskip-\dp\strutbox
3\fqdv\fqdv

\vskip-\prevdepth\vskip\dp\strutbox

\begin{longtable}{cc}
\color{red}4\fqdv\fqdv&\color{red}\fqdv\fqdv
\end{longtable}

5\fqdv\fqdv

\fqdv\fqdv

\begin{tabular}{cc}
\color{blue}\fqdv\fqdv&\color{blue}\fqdv\fqdv
\end{tabular}

\fqdv\fqdv
\end{document}

-