In my Sphinx project, I have description lists that start with either a paragraph or a list. Since I want the description term to be on its own line, I use enumitem
with {style=nextline}
. The problem is that this causes an extra line of space to appear after the term if an itemize list follows. Being auto-generated by Sphinx, though, I'm limited to setting options in the preamble to fix it. Does such a fix exist that prevents the extra space?
\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}
Update: To solve the problem at hand I have the Makefile applying karlkoeller's fix across the entire file. However, this post on changing behaviour depending on environment helped me come up with this solution that almost works.
\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}
What's supposed to happen is the code passed to before
is run wherever an itemize
list starts to determine if it's inside a description
, and apply the fix if necessary. However, it's returning the false condition (\ldots
) each time because the code is being evaluated in the preamble, rather than the document itself. I figure expandafter
is the answer, but I couldn't get it to work.
itemize
, inside thedescription
. At that point,\@currenvir
is "itemize", so the comparison to "description" is false. You might ask the description environment to record its name and nesting level in some macros, and then itemize can test those macros to see if (1) it is inside a description and (2) its own nesting level is one greater than the description's.