如何在描述环境中使用空项目?

如何在描述环境中使用空项目?

我使用description环境来为这些项目提供一些额外的理由。但是,有些项目是显而易见的,不需要理由。将它们留空会留下一个大空白行,因为我已将描述设置为下一行

\documentclass[12pt]{report}

\usepackage{enumitem} % configure labels of items in enumerations i.e. i), ii)
\setlist[description]{style=nextline,font=\normalfont\textbullet\space,labelindent=\parindent}

\begin{document}
\begin{description}
    \item[Obvious item]
    \item[Not so obvious] So we need a small reason, which can span multiple lines lines lines lines lines lines lines lines lines lines lines lines
    \item[Also obvious]
\end{description}
\end{document}

姆韦

如果我做错了,欢迎任何建议!:)。

编辑:迄今为止最丑陋的黑客方法是使用\item[Obvious item\vspace{-1.5em}]哪个seems right to my eye™️

补充:我使用descriptionwith 是nextline因为这种方式尊重逻辑格式,而且我打算稍后改进样式(例如将术语加粗)。如果我使用诸如itemize手动换行符之类的替代方法,这将(我认为)更加困难

也许我可以修补description以检测空的物品描述?

答案1

按摩身体,让您焕然一新descriptionitemize并获得正确的身体调整)。

\documentclass[12pt]{report}
\usepackage{environ,xparse}

\ExplSyntaxOn
\NewEnviron{ctdescription}
 {
  % remove possible \par generated by blank lines before \item
  \tl_replace_all:Nnn \BODY { \par\item } { \item }
  % add a trailing delimiter
  \tl_put_right:Nn \BODY { \ct_item_end: }
  % replace \item by \ct_item_end: \ct_item:w
  \tl_replace_all:Nnn \BODY { \item } { \ct_item_end: \ct_item:w }
  % remove the spurious leading \ct_item:w
  \tl_set:Nx \BODY { \tl_tail:N \BODY }
  % produce the environment
  \begin{itemize}\BODY\end{itemize}
 }
\cs_new_protected:Npn \ct_item:w [#1] #2 \ct_item_end:
 {
  \item #1 \tl_if_blank:nF { #2 } { \mbox{} \\ \tl_trim_spaces:n { #2 } }
 }
\ExplSyntaxOff

\begin{document}

\begin{ctdescription}
\item[Obvious item]
\item[Not so obvious] No we need a small reason, which can 
  span multiple lines lines lines lines lines lines lines 
  lines lines lines lines lines
\item[Also obvious]
\end{ctdescription}

\end{document}

请注意,不允许有尾随空行,但允许在 之前有空行\item

在此处输入图片描述

答案2

一个更加临时的建议:为什么不完全忘记描述?

\documentclass[12pt]{report}

\begin{document}

\begin{itemize} 
    \item Obvious item
    \item Not so obvious \\
          So we need a small reason, which can span multiple lines lines lines lines lines lines lines lines lines lines lines lines
    \item Also obvious
\end{itemize}

\end{document}

这应该会产生显示的输出。

答案3

一个非常临时的建议:忘记nextline

\documentclass[12pt]{report}

\usepackage{enumitem} % configure labels of items in enumerations i.e. i), ii)
\setlist[description]{font=\normalfont\textbullet\space,labelindent=\parindent}

\begin{document}
\begin{description}
    \item[Obvious item]
    \item[Not so obvious]~\\ So we need a small reason, which can span multiple lines lines lines lines lines lines lines lines lines lines lines lines
    \item[Also obvious]
\end{description}
\end{document}

在此处输入图片描述

相关内容