
문맥: 수직 간격과 관련하여 목록(항목화, 열거 및 설명)을 일반 텍스트처럼 처리하고 싶습니다. 즉:
- 목록이 단락으로 시작하는 경우 세로 간격을
\parskip
미리 삽입하세요. 그렇지 않으면 세로 간격을 두지 마세요.- 목록 항목 사이에 세로 간격이 없습니다.
- 목록이 단락으로 끝나면
\parskip
그 뒤에 수직을 삽입하세요. 그렇지 않으면 수직 간격은 없습니다.
나는 특히 다음에서 찾은 정보를 사용했습니다.\topsep, \itemsep, \partopsep 및 \parsep - 각각의 의미는 무엇입니까?.
요구사항 #1은 으로 해결됩니다 \setlist{topsep=-\parskip,partopsep=\parskip}
.
요구사항 #2는 으로 해결됩니다 \setlist{noitemsep}
.
문제: 요구 사항 #3에는 두 가지 문제가 남아 있습니다.
- 수직 공간이 추가됩니다.~ 후에후자가 단락을 시작하는 경우 목록입니다. 이 목록이즉시텍스트가 이어집니다. (즉, 독립적인 길이 같은 것은 없습니다
parbottomsep
). - 만약새로운단락은 목록 다음에 시작됩니다. 이 단락은아니다.
\parskip
질문:
요구 사항 #3을 준수하는 방법은 무엇입니까?
(현재 수동 패치를 사용하고 있습니다(아래 MWE 참조). 물론 만족스럽지는 않습니다.)
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}