%3F.png)
Contexto: Quiero tratar las listas (detallar, enumerar y describir) como texto normal en lo que respecta al espaciado vertical. A saber:
- Si la lista comienza con un párrafo, inserte una vertical
\parskip
de antemano; de lo contrario, no habrá espacio vertical;- Sin espacios verticales entre elementos de la lista;
- Si la lista termina un párrafo, inserte una vertical
\parskip
después; de lo contrario, no habrá espacio vertical.
En particular, he utilizado información que se encuentra en\topsep, \itemsep, \partopsep y \parsep: ¿qué significa cada uno de ellos?.
El requisito número 1 se resuelve con \setlist{topsep=-\parskip,partopsep=\parskip}
.
El requisito 2 se resuelve con \setlist{noitemsep}
.
Problema: Quedan dos problemas con el Requisito n.° 3:
- Se añade un espacio vertical.despuésla lista si este último comienza un párrafo, incluso si esta lista esinmediatamenteseguido del texto. (Es decir, no existe una
parbottomsep
longitud idependiente). - si unnuevoEl párrafo comienza después de la lista, este párrafo.no esprecedido de un
\parskip
.
Pregunta:
¿Cómo cumplir con el Requisito #3?
(Actualmente uso parches manuales; consulte MWE a continuación, pero, por supuesto, no es satisfactorio).
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}
Respuesta1
Este no es menos sucio, pero utiliza las herramientas proporcionadas por enumitem
, jugando con la after
clave:
\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}
Respuesta2
Aquí hay una posible solución usando lua para obtener la siguiente línea en la fuente y verificar su vacío. Eso sí, sólo funciona con lualatex. Es posible que necesite un poco de refinamiento para líneas casi vacías (¿solo espacios?).
\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}