Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I define a marco \mycmd like this

\newcommand\mycmd[2]{{some complicated format #1}&{some complicated format #2}\\}

to simply 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.
share|improve this question
    
\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

1 Answer 1

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
  \addrow{contentA1}{contentA2}
  \addrow{contentB1}{contentB2}
  \addrow{contentC1}{contentC2}
  \addrow{contentZ1}{contentZ2}
%\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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.