使用 style=nextline 时,描述术语和项目列表之间出现空白行

使用 style=nextline 时,描述术语和项目列表之间出现空白行

在我的 Sphinx 项目中,我有以段落或列表开头的描述列表。由于我希望描述术语单独成行,因此我使用了enumitemwith {style=nextline}。问题是,如果后面跟着逐项列表,则会导致术语后面出现一行额外的空格。但由于是 Sphinx 自动生成的,因此我只能在序言中设置选项来修复它。是否存在可以防止出现额外空格的修复方法?

\documentclass{article}
\usepackage{enumitem}
\setlist[description]{style=nextline}

\begin{document}

\begin{description}
\item[{This is a term.}] \leavevmode
This is a description of the term, usually spanning multiple lines,
which should start on its own line.
\end{description}

\begin{description}
\item[{This is a term containing an itemize list.}] \leavevmode
\begin{itemize}
\item {} 
This is an item with too much space between it and the term above.
\end{itemize}
\end{description}

\end{document}

更新:为了解决手头的问题,我让 Makefile 在整个文件中应用 karlkoeller 的修复。然而,这篇关于根据环境改变行为帮助我想出了这个几乎可行的解决方案。

\documentclass{article}
\makeatletter
\def\ifenv#1{
   \def\@tempa{#1}%
   \ifx\@tempa\@currenvir
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
   \fi
}
\makeatother

\usepackage{enumitem}
\setlist[description]{style=nextline}
\setlist[itemize]{before=\ifenv{description}{\vspace*{-1.5\baselineskip}}{\ldots}}

\begin{document}

\begin{description}
\item[{This is a term.}] \leavevmode
This is a description of the term, usually spanning multiple lines, which should start on its own line.
\end{description}

\begin{description}
\item[{This is a term containing an itemize list.}] \leavevmode
\begin{itemize}
\item {} 
This is an item with too much space between it and the term above.
\end{itemize}
\end{description}

Text in between
\begin{itemize}
\item {} 
This is a bare itemize.
\end{itemize}

\end{document}

应该发生的是,传递给的代码beforeitemize列表开始确定它是否在 内时运行description,并在必要时应用修复。但是,它\ldots每次都返回错误条件 ( ),因为代码是在序言中而不是文档本身中进行评估的。我想这expandafter就是答案,但我无法让它工作。

答案1

目前没有更好的想法...

你可以加

\setlist[itemize]{before=\vspace*{-1.5\baselineskip}}

在序言中。

请注意这将影响所有itemize环境......

完整代码:

\documentclass{article}
\usepackage{enumitem}
\setlist[description]{style=nextline}
\setlist[itemize]{before=\vspace*{-1.5\baselineskip}}

\begin{document}

\begin{description}
\item[{This is a term.}] \leavevmode
This is a description of the term, usually spanning multiple lines,
which should start on its own line.
\end{description}

\begin{description}
\item[{This is a term containing an itemize list.}] \leavevmode
\begin{itemize}
\item {}
This is an item with too much space between it and the term above.
\end{itemize}
\end{description}

\end{document} 

输出:

在此处输入图片描述

答案2

我按照 Dan 的建议,通过编程解决了这个问题,即让描述设置一个宏来\indesc指示它处于活动状态,并itemize在其为真时应用修复。然后 itemize 会\indesc全局重置,以防止修复应用于描述中的后续列表。我能看到的唯一警告是描述文本中的文本是否出现在列表之前。

\documentclass{article}
\def\indesc{FALSE}
\makeatletter
\def\ifdesc{
  \def\@istrue{TRUE}%
  \ifx\indesc\@istrue
    \vspace*{-1.0\baselineskip}
    \gdef\indesc{FALSE}
  \fi
}
\makeatother

\usepackage{enumitem}
\setlist[description]{style=nextline,before=\def\indesc{TRUE},after=\def\indesc{FALSE}}
\setlist[enumerate]{before=\ifdesc}
\setlist[itemize]{before=\ifdesc}

\begin{document}

\begin{description}
\item[{This is a term.}] \leavevmode
This is a description of the term, usually spanning multiple lines,
which should start on its own line.
\end{description}

\begin{description}
\item[{This is a term containing two itemize lists.}] \leavevmode
\begin{itemize}
\item {}
This is an itemize list with the extra space above removed.
\end{itemize}
Some text in between.
\begin{itemize}
\item {}
This is an itemize list left untouched.
\end{itemize}
\end{description}

Some text after the description.
\begin{itemize}
\item {}
This is another itemize list left untouched.
\end{itemize}

\end{document}

相关内容