4

I am using two custom list environments (itemize-compact and descriptionhang), which work fine on their own, but not when I nest them.

Please consider this MWE:

\documentclass[a4paper]{article}

\usepackage{letltxmacro}
\usepackage{xargs}
\usepackage{xifthen}
\usepackage{enumitem}

\usepackage{geometry}
\geometry{left=27.5mm,right=27.5mm,bottom=27.5mm,top=27.5mm}

%Line spacing
\usepackage{setspace}
\setstretch{1.115}

%Paragraph indentation & spacing
\usepackage{parskip}
\setlength{\parskip}{2.75ex plus 0.5ex minus 0.2ex}

%Itemize with less spacing
\newenvironment{itemize-compact}
{\vspace{-1.5ex plus 0.2ex}
\begin{itemize}
  \setlength{\itemsep}{-1.5ex plus 0.2ex}}
{\end{itemize}}

%Description environment with newlines and bit of spacing after the item titles
\newenvironment{descriptionhang}{%
  \begin{description}[labelsep=0pt]%
    \LetLtxMacro{\olditem}{\item}%
    \renewcommandx\item[2][1,2]{\olditem\ifthenelse{\isempty{##1}}{}{\hspace{13.5pt}\textbf{##1}}\ifthenelse{\isempty{##2}}{}{\ ##2}\hfill\\[3pt plus 0.75pt minus 1.75pt]}}%
  {\end{description}}

\usepackage{lipsum}

\begin{document}
Itemize-compact non-nested:
\begin{itemize-compact}
\item Blah
\item Bleh
\item \lipsum[2]
\end{itemize-compact}

Itemize-compact nested in a descriptionhang:
\begin{descriptionhang}
\item[Hello world]
\lipsum[2]

\begin{itemize-compact}
\item Blah
\item Bleh
\item \lipsum[2]
\end{itemize-compact}

\item[Foobar]
\lipsum[2]
\end{descriptionhang}

\end{document}

This produces:MWE result

Notice that the itemize-compact environment which is nested in the descriptionhang produces an incorrect result. The bullets are in the right spot but the text is not. Does anyone know how to fix this?

4

The \item macro renewed within descriptionhang is inherited in the nested itemize-compact environment. The same goes for the labelsep specification. Here's a modification to your MWE that keeps the same format when nested:

Nested environments itemize-compact/descriptionhang

\documentclass[a4paper]{article}

\usepackage{letltxmacro}
\usepackage{xargs}
\usepackage{xifthen}
\usepackage{enumitem}

\usepackage{geometry}
\geometry{left=27.5mm,right=27.5mm,bottom=27.5mm,top=27.5mm}

%Line spacing
\usepackage{setspace}
\setstretch{1.115}
\LetLtxMacro{\itcompitem}{\item}% <------- Store copy of \item
%Paragraph indentation & spacing
\usepackage{parskip}
\setlength{\parskip}{2.75ex plus 0.5ex minus 0.2ex}

%Itemize with less spacing
\newenvironment{itemize-compact}
{\vspace{-1.5ex plus 0.2ex}
\LetLtxMacro{\item}{\itcompitem}% <------- Restore copy of \item
\begin{itemize}[labelsep=1ex]% <------- Fixed labelsep
  \setlength{\itemsep}{-1.5ex plus 0.2ex}}
{\end{itemize}}

%Description environment with newlines and bit of spacing after the item titles
\newenvironment{descriptionhang}{%
  \begin{description}[labelsep=0pt]%
    \LetLtxMacro{\olditem}{\item}%
    \renewcommandx\item[2][1,2]{\olditem\ifthenelse{\isempty{##1}}{}{\hspace{13.5pt}\textbf{##1}}\ifthenelse{\isempty{##2}}{}{\ ##2}\hfill\\[3pt plus 0.75pt minus 1.75pt]}}%
  {\end{description}}

\usepackage{lipsum}

\begin{document}
Itemize-compact non-nested:
\begin{itemize-compact}
\item Blah
\item Bleh
\item \lipsum[2]
\end{itemize-compact}

Itemize-compact nested in a descriptionhang:
\begin{descriptionhang}
\item[Hello world]
\lipsum[2]

\begin{itemize-compact}
\item Blah
\item Bleh
\item \lipsum[2]
\end{itemize-compact}

\item[Foobar]
\lipsum[2]
\end{descriptionhang}

\end{document}​

\item is stored outside any of the environments to obtain a "clean" version. Also, itemize-compact is set with a fixed labelsep of 1ex, allowing a constant separation even when it is nested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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