2

I use enumitem description style nextline to emulate a sort of TOC entry with the following code:

\documentclass{article}
\usepackage{enumitem}

\newenvironment{DLdescription}[1][*]{%
  \newcommand{\DLitem}[2][]{%
    \item[##1\hfill\emph{##2}]
  }
  \begin{description}[style=nextline,leftmargin=#1]%
}{\end{description}}

\begin{document}

  \begin{DLdescription}
  \DLitem[dleft1]{dright1}
    blah blah
    \begin{itemize}
    \item nested item correctly starts on its own line
    \end{itemize}
      \DLitem[dleft2]{dright2}
    % nothing before itemize
    \begin{itemize}
    \item nested item shouldn't start on description label's line!
    \end{itemize}
  \end{DLdescription}

\end{document}

The trouble comes on the second description item which starts straight away with an itemize: the nested item appears on the same line :-(

output of code sample

A workaround found elsewhere suggests to append a \hfill to the relevant label, in my case that would patch command DLitem with

\item[##1\hfill\emph{##2}]\hfill

which, gives a non satisfactory results, as too much vertical space is added between the description label's line and the first nested item:

output of patched code

How to obtain the result in the second image without any extra vertical space?

2 Answers 2

3

I think you are misusing the nextline style. I would suggest that you do it like this:

\documentclass{article}
\usepackage{enumitem}

\newcommand{\DLitem}[2][]{%
 \item[#1]\hfill \emph{#2}\par}

\newenvironment{DLdescription}[1][*]
 {\begin{description}[leftmargin=#1]}
 {\end{description}}

\begin{document}

  \begin{DLdescription}
  \DLitem[dleft1]{dright1}
    blah blah
    \begin{itemize}
    \item nested item correctly starts on its own line
    \end{itemize}
      \DLitem[dleft2]{dright2}
    % nothing before itemize
    \begin{itemize}
    \item nested item shouldn't start on description label's line!
    \end{itemize}
  \end{DLdescription}

\end{document}

You can adjust locally \parskip is you want less space after the first line.

1
  • Very neat, indeed! A last optimization could be inserting a \parskip only if a nested environment is detected, how to do that?
    – sphakka
    Jun 14, 2012 at 20:45
1

Here's a manual adjustment that works:

enter image description here

\documentclass{article}
\usepackage{enumitem}% http://ctan.org/pkg/enumitem

\newcommand{\DLitem}[2][]{%
  \item[#1\hfill\emph{#2}]
}
\newenvironment{DLdescription}[1][*]{%
  \begin{description}[style=nextline,leftmargin=#1]%
}{\end{description}}

\begin{document}

  \begin{DLdescription}
  \DLitem[dleft1]{dright1}
    blah blah
    \begin{itemize}
    \item nested item correctly starts on its own line
    \end{itemize}
      \DLitem[dleft2]{dright2}
    \hfill\\[\dimexpr-2\baselineskip-\topsep]
    \begin{itemize}
    \item nested item shouldn't start on description label's line!
    \end{itemize}
  \end{DLdescription}

\end{document}​

Inserting a blank line \null\hfill, followed by a vertical skip equivalent to the start of the description plus an extra \baselineskip: \\[\dimexpr-2\baselineskip-\topsep]

1
  • Thanks, but I'd like a patch for my \DLitem command. I can't put your solution there as it screws other items with some text before any nested environment...
    – sphakka
    Jun 14, 2012 at 16:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .