我正在尝试自定义enumitem
标签和当项目内容对于指定空间来说太长时,它们将被分成具有负(悬挂)缩进的段落:
label one content one |
label two content two content two content|
two content two content|
two content two content|
two |
label three label three label |
three label three label |
three content three |
label four content four |
以下适用于“内容”部分,但标签未缩进,并且以下标签打印在前一行的顶部。
后者可以通过\\
在“内容三”后添加来手动解决,但由于我想在部分自动化的工作流程中使用它,因此我希望有一种不需要手动完成的解决方案。
有没有办法实现这enumitem
一点?如果没有,那该怎么办?
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{calc,enumitem}
\newlist{pardesc}{description}{1}
\setlist[pardesc]{%
nosep,
labelindent=2cm,
labelsep*=1cm,
labelwidth=.5\textwidth-1.5cm, %i.e. same with for both
leftmargin=\labelwidth+5cm,
style=standard,
align=parleft,
}
\begin{document}
\begin{pardesc}
\item[label one] content one
\item[label two] content two content two content two content two content two content two content two
\item[label three label three label three label three label three] content three
\item[label four] content four
\end{pardesc}
\end{document}
编辑:
这些列表中经常会有脚注和分页符,因此使用 tabular
不是一个可行的解决方案。
答案1
在文件中的enumitem.sty
一个def如下:
\def\enit@align@parleft{%
\def\enit@align##1{%
\nobreak
\strut\smash{\parbox[t]\labelwidth{\raggedright##1}}}}
在您的序言中,您可以尝试删除\smash
并将 放入\strut
内\parbox
。\hangindent
可能满足您的要求,但您可能需要一些可变长度。将\parbox
对齐方式更改为[b]
。
\makeatletter
\def\enit@align@parleft{%
\def\enit@align##1{%
\nobreak
{\parbox[b]\labelwidth{\hangindent2.5em\raggedright##1\strut}}}}
\makeatother
我不知道这是否会干扰任何其他功能,它仅在您的示例中进行了测试。
答案2
您可以使用tabular
并定义新列来简化您的工作。
\newcolumntype{D}[1]{>{\bfseries\raggedright\hangindent1.5em\arraybackslash}p{#1}}
\newcolumntype{E}[1]{>{\raggedright\hangindent1.5em\arraybackslash}p{#1}}
完整代码:
\documentclass{article}
\usepackage{array}
\newcolumntype{D}[1]{>{\bfseries\raggedright\hangindent1.5em\arraybackslash}p{#1}}
\newcolumntype{E}[1]{>{\raggedright\hangindent1.5em\arraybackslash}p{#1}}
\usepackage[showframe]{geometry}
\begin{document}
\noindent
\begin{tabular}{@{}D{.47\textwidth}E{.5\textwidth}@{}}
label one & content one \\
label two & content two content two content two content two content two content two content two content two content two content two content two content two content two content two \\
label three label three label three label three label three & content three \\
label four & content four
\end{tabular}
\end{document}
答案3
通过longtabu
对 Harish 的答案进行改进,您可以获得:
编辑:已编辑以显示兼容性\pagebreak
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{array}
\usepackage{tabu, longtable}
\newcolumntype{D}[1]{>{\bfseries\raggedright\hangindent1.5em\arraybackslash}p{#1}}
\newcolumntype{E}[1]{>{\raggedright\hangindent1.5em\arraybackslash}p{#1}}
\tabulinesep=^1.5mm_1.5mm
\begin{document}
\noindent
{\centering
\begin{longtabu} to \linewidth {@{}D{.47\textwidth} E{.5\textwidth}@{}}
\endhead
\endfoot
\endlastfoot
label one & content one \\
label two & content two content two content two content two content two content two content two content two content two content two content two content two content two content two \\
label three label three label three label three label three & content three \\
label four & content four\footnotemark \\
label one & content one \\
label two & content two content two content two content two content two content two content two content two content two content two content two content two content two content two \\
label three label three label three label three label three & content three \\
label four & content four \\
label one & content one \\
label two & content two content two content two content two content two content two content two content two content two content two content two content two content two content two \\
label three label three label three label three label three & content three \\
label four & content four \\
label one & content one \\
label two & content two content two content two content two content two content two content two content two content two content two content two content two content two content two \\
label three label three label three label three label three & content three \\
label four & content four \\
label one & content one\footnotemark \\
label two & content two content two content two content two content two content two content two content two content two content two content two content two content two content two \\
label three label three label three label three label three & content three \\
label four & content four \\
label one & content one \\
label two & content two content two content two content two content two content two content two content two content two content two content two content two content two content two \\
label three label three label three label three label three & content three \\
label four & content four \\
label one & content one \\
\pagebreak
label two & content two content two content two content two content two content two content two content two content two content two content two content two content two content two \\
label three label three label three label three label three & content three \\
label four & content four \\
\end{longtabu}
\footnotetext[1]{text one}
\footnotetext[2]{text two}
\end{document}
这是一个包含脚注的 3 页表格和一个\pagebreak