2

Consider the following MWE, where I use the titlesec package to add negative spacing before a section heading. (I've exaggerated the negative space for effect). It works as expected in general, except it doesn't work after a section consisting of only a longtable. Any advice?

\documentclass[11pt]{article}
\usepackage{longtable}
\usepackage{titlesec}
\usepackage{lipsum}

\titlespacing{\section}{0pt}{-24pt}{0pt}  %exaggerated

\begin{document}

\lipsum[66]

\section{Section with text before table}

\lipsum[66]

\begin{longtable}{l|l}
    a & b \\
    c & d \\
\end{longtable}

\section{Section with longtable only}

\begin{longtable}{l|l}
    a & b \\
    c & d \\
\end{longtable}

\section{Section with text only}

\lipsum[66]

\end{document}

output

  • Welcome to TeX.SX! Good example! – egreg Jan 23 '18 at 22:18
  • It has to do with \@afterheading. Evidently longtable does not "consume" its effects. \leavevmode will take care of it. – John Kormylo Jan 24 '18 at 16:41
  • Thanks @JohnKormylo! Adding \leavevmode immediately after \section{Section with longtable only} fixed the problem. – whao Jan 25 '18 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.