5

Context: I want to treat lists (itemize, enumerate, and description) just like regular text for what regards vertical spacing. Namely:

  1. If the list starts a paragraph, insert a vertical \parskip beforehand — no vertical spacing otherwise;
  2. No vertical spacing between items of the list;
  3. If the list ends a paragraph, insert a vertical \parskip afterwards — no vertical spacing otherwise.

I have notably used information found in \topsep, \itemsep, \partopsep and \parsep - what does each of them mean.

Requirement #1 is solved with \setlist{topsep=-\parskip,partopsep=\parskip}.

Requirement #2 is solved with \setlist{noitemsep}.

Problem: There remain two issues with Requirement #3:

  • A vertical space is added after the list if the latter starts a paragraph, even if this list is immediately followed by text. (I.e. there is no such thing as an idependent parbottomsep length).
  • If a new paragraph starts after the list, this paragraph is not preceded with a \parskip.

Question: How to comply with Requirement #3?
(I currently use manual patches — see MWE below — but it is of course not satisfactory.)

enter image description here


MWE

\documentclass[parskip=half]{scrartcl}
    \usepackage{enumitem}
    \setlist{%
        topsep=-\parskip,
        partopsep=\parskip,
        noitemsep,
    }
\begin{document}
    This sentence is a paragraph on its own; there is thus a vertical parskip prior next paragraph.

    Following list is \emph{within} a paragraph, with preceding and appended text.
    \begin{itemize}
        \item One,
        \item Two,
        \begin{itemize}
            \item Two and a half;
            \item Almost three.
        \end{itemize}
        \item Three.
    \end{itemize}
    This text is appended to the previous list.
    However, following list starts a new paragraph on its own.

    \begin{enumerate}
        \item Did you notice the vertical spacing preceding this list?
        \item Two,
        \begin{enumerate}
            \item Two and a half;
            \item Almost three.
        \end{enumerate}
        \item Three.
    \end{enumerate}
%   \vspace{-\parskip}                                  %quick and dirty solution
    \textbf{There shouldn't be a vertical spacing here.}
    This text is appended to the previous list too.

    And finally, a list with preceding text only.
    \begin{itemize}
        \item One,
        \item Two,
        \begin{itemize}
            \item Two and a half;
            \item Almost three.
        \end{itemize}
        \item Three.
    \end{itemize}

%   \null\par                                            %quick and dirty solution
    \textbf{There should be a vertical spacing here.}
    This is a new paragraph.
    It should thus be preceded with parskip.
\end{document}
3

This is hardly less dirty, but it uses the tools provided by enumitem, playing with the after key:

\documentclass[parskip=half]{scrartcl}
\usepackage{enumitem}
\setlist{%
    topsep=-\parskip,
    partopsep=\parskip,
    noitemsep,
}

\begin{document}

This sentence is a paragraph on its own; there is thus a vertical parskip prior next paragraph.

Following list is \emph{within} a paragraph, with preceding and appended text.
\begin{itemize}
    \item One,
    \item Two,
    \begin{itemize}
        \item Two and a half;
        \item Almost three.
    \end{itemize}
    \item Three.
\end{itemize}
This text is appended to the previous list.
However, following list starts a new paragraph on its own.

\begin{enumerate}[after =\vspace*{-\partopsep}]
    \item Did you notice the vertical spacing preceding this list?
    \item Two,
    \begin{enumerate}
        \item Two and a half;
        \item Almost three.
    \end{enumerate}
    \item Three.
\end{enumerate}
\textbf{There shouldn't be a vertical spacing here.}
This text is appended to the previous list too.

And finally, a list with preceding text only.
\begin{itemize}[after = \vspace*{\partopsep}]
    \item One,
    \item Two,
    \begin{itemize}
        \item Two and a half;
        \item Almost three.
    \end{itemize}
    \item Three.
\end{itemize}


\textbf{There should be a vertical spacing here.}
This is a new paragraph.
It should thus be preceded with parskip.

\end{document} 

enter image description here

  • That's indeed more semantically correct! – ebosi Feb 10 '18 at 1:01

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.