自定义枚举/逐项环境中的适当边距

自定义枚举/逐项环境中的适当边距

我正在使用两个自定义列表环境(itemize-compactdescriptionhang),它们本身运行良好,但嵌套时则不行。

请考虑这个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}

得出的结果为:MWE 结果

请注意,itemize-compact嵌套在 中的环境descriptionhang会产生不正确的结果。项目符号在正确的位置,但文本不在。有人知道如何解决这个问题吗?

答案1

在嵌套环境中\item,内部更新的宏会被继承。规范也是如此。以下是对您的 MWE 的修改,在嵌套时保持相同的格式:descriptionhangitemize-compactlabelsep

嵌套环境 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被储存了外部任何环境都可以获得“干净”的版本。此外,itemize-compact设置为固定的labelsep1ex即使在嵌套时也允许常量分离。

相关内容