1

Special situation, using longtable inside my custom class. When I use \longtable, \end{longtable} instead of \begin{longtable}, \end{longtable}, I get bad margins when the longtable is inside a list environment.

Test document:

  \documentclass{article}
  \usepackage{longtable}
  \begin{document}
  text
  \begin{itemize}
    \item first text
    \begin{longtable}{c}%
      table col1
    \end{longtable}%
      \item second text
    \longtable{c}
    table col2
    \endlongtable
    \item third text
  \end{itemize}
  text
  \end{document}

See how the "third text" is out of margin?

I can't remember why I used that syntax when I wrote the class, probably so I got no extra vertical space.

I trace the issue to line 199 in longtable.sty -- if the \endgraf command is replaced with \par, the margins are okay again. Interestingly, \meaning{endgraf} shows that its meaning is \par.

Is it reasonable to replace the \endgraf with \par? If I must change the code to use \begin and \end, do I need to adjust for vertical spacing? I read the code in source2e about the \begin and \end commands but it looks pretty deep.

8
  • Do you really need a longtable in an itemize list?
    – user31729
    Sep 14, 2015 at 18:07
  • 1
    By the way: \longtable screws up the spacings there. You've lost grouping and all spacings go mental
    – user31729
    Sep 14, 2015 at 18:12
  • don't do that ! Sep 14, 2015 at 18:14
  • 1
    well that was my initial response. since then I looked at the code and actually it's not as bad as I thought as longtable does group its definitions, I thought it was relying on begin/end. certainly in general you can not rely on using \foo syntax instead of \begin{foo}. the interesting thing you should be showing is \show\par to see what \par is at that point, \show\endgraf will always say \par that is the point, \par can mean anything (and in tables can mean nothing (\@empty)) in any case whatever happens if you use that syntax you are on your own it has never been tested in that usage:-) Sep 14, 2015 at 18:34
  • 1
    If I run your example with \show\par on line 199 of lt I get > \par=macro: ->\if@newlist \advance \par@deathcycles \@ne \ifnum \par@deathcycles >\@m \@noitemerr {\@@par }\fi \else {\@@par }\fi actually that's probably safe enough if you must be in a list. Sep 14, 2015 at 18:49

1 Answer 1

2

It's possible to control the spacings of a longtable environment with the length variables \LTleft and \LTright.

Since a first item level is used, it's perhaps an idea to set \setlength{\LTleft}{\dimexpr\leftmargini+\relltshift}, where \relltshift is some user specified shift relativ to the left margin indent.

 \documentclass{article}


 \usepackage{longtable}

 \newlength{\relltshift}

 \setlength{\relltshift}{\labelwidth}
 \setlength{\LTleft}{\dimexpr\leftmargini+\relltshift}

 \begin{document}
 text
  \begin{itemize}
  \item first text
    \begin{longtable}{c}%
      table col1
    \end{longtable}%
  \item second text
    \begin{longtable}{c}
    table col2
    \end{longtable}
  \item third text
  \end{itemize}
  text
\end{document}
2
  • my question is a simplified version of what's going on but it does show the problem. I understand I can shift the table in this case since we know it is in a list but this is for a custom class and I don't know in which environments the longtable will be used.
    – Tim A
    Sep 14, 2015 at 18:13
  • @TimA you don't need to know you are in a list, just always set \LTleft to \@totalleftmargin plus 1fill and it should work in or out of a list. Sep 14, 2015 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .