我使用该enumitem
包来定制描述列表。下面是 MWE 打印的一些虚构的个人信息:
\documentclass{article}
\usepackage{enumitem}
\setlist[description]{leftmargin=5em, labelindent=0em, labelwidth=4.5em,
align=right}
\begin{document}
\begin{description}
\item[Address]
3 Whole St, Wondertown WXY 2722
\item[Email]
[email protected]
\item[Phone]
123 55 66 78
\item[Secondary Phone]
123 78 66 55
\item[Nationality]
Wonderland, Republic of Home and Mother Country
\item[Security Clearance]
National Clearance 13.2 with a very, very, very,
very, very, very, very, very, very, very, very,
very, very, very, very long explanation
\end{description}
\end{document}
输出基本上是这样的:
Address 3 Whole St, Wondertown WXY 2722
Email [email protected]
Phone 123 55 66 78
Secondary Phone 123 78 66 55
Nationality Wonderland, Republic of Home and Mother Country
Security Clearance National Clearance 13.2 with a very, very, very,
very, very, very, very, very, very, very, very, very,
very, very, very long explanation
有些标签不适合 - 当然\setlist[description]
我可以增加必要的尺寸,但我宁愿不移动标签/文本分隔的位置。相反,我希望标签能够换行在标签区域像这样的多行:
Address 3 Whole St, Wondertown WXY 2722
Email [email protected]
Phone 123 55 66 78
Secondary 123 78 66 55
Phone
Nationality Wonderland, Republic of Home and Mother Country
Security National Clearance 13.2 with a very, very, very,
Clearance very, very, very, very, very, very, very, very, very,
very, very, very long explanation
理想情况下,标签中的换行符会自动出现在空格处。有没有办法用enumitem
或其他方式实现这一点?
注 1:我看到了 stackexchange 上的问题“强制项目内的长文本换行”,但我无法让它适用于我的情况。
笔记2:我不想改变我使用的环境。tabular
类似的环境当然可以很好地适应,但是整个输入文本已经在描述列表中设置了,所以我想保持这种方式。
答案1
您可以定义一种类似于多线的新样式,但是
- 你必须设置更好的标签宽度和
\\~
如果描述文本太短,则必须插入空行。\documentclass{article} \usepackage{enumitem,calc} \makeatletter \def\enit@align@parright{% \def\enit@align##1{% \nobreak \strut\smash{\parbox[t]\labelwidth{\raggedleft##1}}}} \def\enit@style@multilineright{% \enit@align@parright \enit@calcset\labelindent\z@{0pt}% \enit@calcset\leftmargin\thr@@!} \makeatother \setlist[description]{labelwidth=\widthof{\bfseries Nationality}, style=multilineright} \begin{document} \noindent xxxxxxx \begin{description} \item[Address] 3 Whole St, Wondertown WXY 2722 \item[Email] [email protected] \item[Phone] 123 55 66 78 \item[Secondary Phone] 123 78 66 55\\~ \item[Nationality] Wonderland, Republic of Home and Mother Country \item[Security Clearance] National Clearance 13.2 with a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long explanation \end{description} \end{document}