2

Given the following minimal example

\documentclass[parskip=full]{scrreprt}
\usepackage[onehalfspacing]{setspace}
\usepackage{enumitem}
\usepackage{lipsum}

\setlist{
parsep=\parsep,
itemsep=-.5\parsep,
topsep=-.5\parsep,
partopsep=.5\parsep
}

\begin{document}
\lipsum[1]
\begin{itemize}
\item list
\item between
\item paragraphs
\end{itemize}
\lipsum[2]

\begin{itemize}
\item list
\item in
\item own
\item paragraph
\end{itemize}

\lipsum[3]
\begin{itemize}
\item list
\item above
\item paragraph
\end{itemize}

\lipsum[4-5]
\end{document}

The first and second lists are spaced as expected, with the second list spaced as an individual paragraph (compare with last two paragraphs). However, the third list is spaced in the same way as the first one, even though it is followed by an unrelated paragraph.

This answer states that \partopsep is added above and below a list environment if it begins a new paragraph. Is there a (reasonably simple) way to get a \partopsep added only to the bottom if a list environment is followed by a new paragraph?

2
+50

Interesting question. Here's my attempt at a solution. You have to enable it for a particular list by adding first={\useparbotsep}. It modifies one macro from latex.ltx (\@doendpe), but hopefully in a way that only makes a difference when \useparbotsep is called.

It only works for top level lists. Subsequent level lists behave as normal.

\documentclass[parskip=full]{scrreprt}
\usepackage[onehalfspacing]{setspace}
\usepackage{enumitem}

\makeatletter
\newskip\bottomsepadd
\newif\ifparbotsep
\def\useparbotsep{%
  \ifnum\@listdepth=\@ne
    \global\bottomsepadd\partopsep
    \global\@topsepadd\topsep
    \global\parbotseptrue
  \fi}
\def\@doendpe{% <- modified from latex.ltx (hopefully with no side effects)
  \@endpetrue
  \def\par{\@restorepar
    \clubpenalty\@clubpenalty
    \everypar{}%
    \ifparbotsep
      \ifnum\@listdepth=\z@
        \if@endpe\vskip\bottomsepadd\fi
        \global\parbotsepfalse
      \fi
    \fi
    \par\@endpefalse}
    \everypar{{\setbox\z@\lastbox}%
      \everypar{}\@endpefalse}}
\makeatother

\setlist{
  parsep=\parsep,
  itemsep=-.5\parsep,
  topsep=-.5\parsep,
  partopsep=.5\parsep,
  first={\useparbotsep}
}

\begin{document}

\vskip 5pt\hrule\vskip 5pt

List within paragraph:
\begin{itemize}
  \item List item.
  \item List item.
  \item List item.
\end{itemize}
End of List within paragraph.

\vskip 5pt\hrule\vskip 5pt

List as its on paragraph:

\begin{itemize}
  \item List item.
  \item List item.
  \item List item.
\end{itemize}

Paragraph following list as its own paragraph.

\vskip 5pt\hrule\vskip 5pt

List above paragraph:

\begin{itemize}
  \item List item.
  \item List item.
  \item List item.
\end{itemize}
Text following list.

\vskip 5pt\hrule\vskip 5pt

List below paragraph:
\begin{itemize}
  \item List item.
  \item List item.
  \item List item.
\end{itemize}

Paragraph following list.

\vskip 5pt\hrule\vskip 5pt
\end{document}

output

4
  • Interesting step towards a solution, but if a call has to be made manually, it would probably be simpler to just add a \vspace
    – Joe
    Mar 4 '19 at 14:54
  • @Joe, well its better than that. It figures out whether you need the vspace for each list environment. And you only have to set up the lists once in your preamble. \@doendpe is used for many things. So you have to restrict it to lists somehow and extra calculations have to be done at the start of the list. Mar 4 '19 at 15:04
  • Sorry, Must have misread the answer (on my phone right now). I’ll check it out in more detail later.
    – Joe
    Mar 4 '19 at 15:09
  • @Joe, it doesn't work with nested lists :(. Perhaps I (or someone else) can work it out. Mar 5 '19 at 0:51

Your Answer

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

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