リストを通常のテキストのように扱うにはどうすればよいでしょうか (垂直間隔に関して)?

リストを通常のテキストのように扱うにはどうすればよいでしょうか (垂直間隔に関して)?

コンテクスト: 垂直方向の間隔に関しては、リスト (項目別、列挙、説明) を通常のテキストと同じように扱いたいと考えています。具体的には、次のようになります。

  1. リストが段落の先頭にある場合は、\parskipその前に垂直方向のスペースを挿入します。それ以外の場合は、垂直方向のスペースは挿入されません。
  2. リストの項目間に垂直方向の間隔はありません。
  3. リストが段落を終了する場合は、\parskipその後に垂直方向のスペースを挿入します。それ以外の場合は、垂直方向のスペースは挿入されません。

私は特に、\topsep、\itemsep、\partopsep、\parsep - それぞれの意味は何ですか

要件 #1 は で解決されます\setlist{topsep=-\parskip,partopsep=\parskip}

要件 #2 は で解決されます\setlist{noitemsep}

問題: 要件 3 には 2 つの問題が残っています。

  • 垂直スペースが追加されます後者が段落の始まりである場合、このリストはすぐにテキストが続きます。(つまり、独立した長さというものは存在しませんparbottomsep)。
  • もし新しい段落はリストの後に始まり、この段落はではありませんの前に が付きます\parskip

質問: 要件 3 に準拠するにはどうすればよいでしょうか?
(現在は手動パッチを使用していますが (下記の 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}

答え1

これはそれほど汚いものではありませんが、 が提供するツールを使用しenumitem、キーを操作しますafter

\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} 

ここに画像の説明を入力してください

答え2

lua を使用してソースの次の行を取得し、その行が空かどうかをチェックする解決策がここにあります。もちろん、これは lualatex でのみ機能します。準空行 (スペースのみ?) の場合は、少し改良する必要があるかもしれません。

\documentclass{article}

\usepackage{luacode}
\begin{luacode*}
function manageNextLine(s)
  luatexbase.remove_from_callback("process_input_buffer", "manageNextLine")
  if s == "" then
    return "\\leavevmode\\par"
  else
    return s
  end
end
\end{luacode*}

\parskip=10ex  % to see it better

\usepackage{enumitem}
\setlist{noitemsep,
         topsep=-\parskip,
         partopsep=\parskip,
         after=\luadirect{luatexbase.add_to_callback("process_input_buffer", manageNextLine , "manageNextLine")}
  }



\begin{document}
Para

Para2
\begin{itemize}
\item 1
\item 2
\end{itemize}
%
Continuing the same para.

Para3
\begin{itemize}
\item A.
\item B.
\end{itemize}

Suite with vertical spacing.

\end{document}

関連情報