在描述环境中正确缩进

在描述环境中正确缩进

我想创建一个如下所示的描述枚举:

keyword 1: Short Description of the keyword
           A characterization of the keyword
keyword 2: Short Description of the keyword
           A characterization of the keyword

举个例子:

Animal 1: Lion
          A lion is ...
Animal 2: Elephant
          An elephant is ...

我尝试了以下

\begin{description}
    \item[Animal1: Lion]\hfill \\
    A lion is ...
    \item[Animal2: Elephant]\hfill \\
    An elephant is ...
\end{description}

问题在于文本“狮子是...”与单词“狮子”不对齐。

您能否给我一些建议,如何创建这样的环境,让我可以为 item 命令提供第二个参数,用于简短描述,然后将其与特征文本正确对齐?顺便说一下,我正在使用 koma 类 scrbook。

答案1

取自这个很好的答案

% arara: pdflatex 

\documentclass{scrbook}
\usepackage{calc}
\makeatletter
\newcommand{\DESCRIPTION@original@item}{}
\let\DESCRIPTION@original@item\item
\newcommand*{\DESCRIPTION@envir}{DESCRIPTION}
\newlength{\DESCRIPTION@totalleftmargin}
\newlength{\DESCRIPTION@linewidth}
\newcommand{\DESCRIPTION@makelabel}[1]{\llap{#1}}%
\newcommand{\DESCRIPTION@item}[1][]{%
  \setlength{\@totalleftmargin}%
       {\DESCRIPTION@totalleftmargin+\widthof{\textbf{#1 }}-\leftmargin}%
  \setlength{\linewidth}
       {\DESCRIPTION@linewidth-\widthof{\textbf{#1 }}+\leftmargin}%
  \par\parshape \@ne \@totalleftmargin \linewidth
  \DESCRIPTION@original@item[\textbf{#1}]%
}
\newenvironment{DESCRIPTION}
  {\list{}{\setlength{\labelwidth}{0cm}%
           \let\makelabel\DESCRIPTION@makelabel}%
   \setlength{\DESCRIPTION@totalleftmargin}{\@totalleftmargin}%
   \setlength{\DESCRIPTION@linewidth}{\linewidth}%
   \renewcommand{\item}{\ifx\@currenvir\DESCRIPTION@envir
                           \expandafter\DESCRIPTION@item
                        \else
                           \expandafter\DESCRIPTION@original@item
                        \fi}}
  {\endlist}
\makeatother
\usepackage{blindtext}

\begin{document}
\begin{DESCRIPTION}
    \item[Animal1:] \textbf{Lion}\\
    A lion is ... \blindtext
    \item[Animal2:] \textbf{Elephant}\\
        An elephant is ...
\end{DESCRIPTION}
\end{document}

在此处输入图片描述

相关内容