enumitem - 描述环境中多行标签的对齐

enumitem - 描述环境中多行标签的对齐

我正在尝试使多行标签右对齐。我将style=multilinealign=right选项应用于 enumitem 描述环境。以下是描述问题的代码:

\documentclass{article}

\usepackage{geometry}
\usepackage{enumitem}

\begin{document}

% multiline, left-aligned
\begin{description}[style=multiline, leftmargin=!, labelwidth=4cm]
    \item[Truth-functional\\ connective] A sentence connective with the property that the truth value of the newly formed sentence is determined solely by the truth value(s) of the constituent sentence(s), nothing more.
\end{description}

% multiline, right-aligned; the option is not applied.
\begin{description}[align=right, style=multiline, leftmargin=!, labelwidth=4cm]
    \item[Truth-functional connective] A sentence connective with the property that the truth value of the newly formed sentence is determined solely by the truth value(s) of the constituent sentence(s), nothing more.
\end{description}

% the order of options changed; different result.
\begin{description}[style=multiline, align=right, leftmargin=!, labelwidth=4cm]
    \item[Truth-functional connective] A sentence connective with the property that the truth value of the newly formed sentence is determined solely by the truth value(s) of the constituent sentence(s), nothing more.
\end{description}

% The label aligned as intended with a single line label.
\begin{description}[align=right, leftmargin=!, labelwidth=4cm]
    \item[Truth-functional] A sentence connective with the property that the truth value of the newly formed sentence is determined solely by the truth value(s) of the constituent sentence(s), nothing more.
\end{description}

\end{document}

在此处输入图片描述

使用单行标签时,没有问题。但使用多行标签时,选项无法正常工作。只有第一个和最后一个选项按预期工作。这段代码中发生了什么?

期望的输出是

在此处输入图片描述

答案1

首先,让我们分析一下您的示例中发生了什么。为此,请注意,如enumitem的文档中所述,multiline相当于style=standard,align=parleft,labelwidth=!

  1. style=multiline, leftmargin=!, labelwidth=4cm

    它按预期工作:具有自动换行的固定宽度标签。由于 ,它是左对齐的parleft

  2. align=right, style=multiline, leftmargin=!, labelwidth=4cm

    style=multiline这与sets完全相同align=parleft,它会覆盖以前的设置。

  3. style=multiline, align=right, leftmargin=!, labelwidth=4cm

    设置align=right实际上撤消了 的中心部分style=multiline(即创建 的部分\parbox)。我不确定为什么,但这会导致Infinite glue shrinkage我在运行您的示例时出错。您没有收到此错误吗?理论上,我本来希望这与下一个案例相同。

  4. align=right, leftmargin=!, labelwidth=4cm

    这里你再次得到了你所期望的:右对齐,但没有\parbox


那么我们如何得到你想要的东西?最直接的选择是创建一个新的对齐方式parright,它的作用与 相同parleft,但使用右对齐方式。我们可以从文档第 6 页复制定义并替换\raggedright\raggedleft

\documentclass{article}

\usepackage{geometry}
\usepackage{enumitem}

\SetLabelAlign{parright}{\strut\smash{\parbox[t]\labelwidth{\raggedleft#1}}}

\begin{document}

% multiline, left-aligned
\begin{description}[align=parright, leftmargin=!, labelwidth=4cm]
    \item[Truth-functional connective] A sentence connective with the property that the truth value of the newly formed sentence is determined solely by the truth value(s) of the constituent sentence(s), nothing more.
\end{description}

\end{document}

MWE 输出

相关内容