具有對齊描述的描述列表

具有對齊描述的描述列表

此論壇主題這正是我正在尋找的。我希望我的描述環境能夠產生這樣的結果:

Label is long   text 
lab2            blalballalaa
label3          possible second rule
label four      hello world

有人提供了這個:

\newenvironment{mydescription}[1]                                                
  {\begin{list}{}%
   {\renewcommand\makelabel[1]{##1:\hfill}%
   \settowidth\labelwidth{\makelabel{#1}}%
   \setlength\leftmargin{\labelwidth}
   \addtolength\leftmargin{\labelsep}}}
  {\end{list}}

效果很好(參數是最長的標籤),但我認為應該enumitem能夠做到這一點。不幸的是,它的文檔讓我非常困惑。有人可以告訴我如何達到相同的結果嗎enumitem

答案1

這是一種可能性:

\documentclass{article}  
\usepackage{calc}  
\usepackage{enumitem}  

\begin{document}

\begin{description}[leftmargin=!,labelwidth=\widthof{\bfseries The longest label}]
  \item[The longest label] text
  \item[Short]  long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text
\end{description}

\end{document}

在此輸入影像描述

答案2

解決方案使用scrextend包(取自維基圖書):

\documentclass[twocolumn]{article}
\usepackage{scrextend}
\begin{document}
\begin{labeling}{alligator}  % alligator is the longest label
    \item [\textbf{ant}]really busy all the time
    \item [chimp] likes bananas
    \item [alligator] very dangerous animal, sharp teeth, long
     muscular tail and a bit of text that is longer than one
     line and shows the alignment of text quite nicely
\end{labeling}
\end{document}

在此輸入影像描述

相關內容