Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
    
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 '12 at 20:45

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]

share|improve this answer
    
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 '12 at 16:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.