![具有对齐描述的描述列表](https://linux22.com/image/254078/%E5%85%B7%E6%9C%89%E5%AF%B9%E9%BD%90%E6%8F%8F%E8%BF%B0%E7%9A%84%E6%8F%8F%E8%BF%B0%E5%88%97%E8%A1%A8.png)
此论坛主题正是我所寻找的。我希望我的描述环境能够产生以下内容:
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
\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}