描述环境中的商品标签太长,超出边距

描述环境中的商品标签太长,超出边距

我正在使用描述环境来处理一组定义。我的一个标签太长,无法放入页面的左边距。我不知道如何在项目标签中强制换行 - 我也不想这么做。有没有办法让描述环境检测标签是否太长并使其换行,以便项目标签仍然右对齐?

注意:我的问题与评论中提到的问题不同,因为我特别希望标签位于边缘,而不是位于页面主体内。

\documentclass[12pt, letterpaper, oneside, draft]{memoir}
\usepackage{enumitem}

% itemize environment configuration
\setlist[itemize]{noitemsep, topsep=0pt}

\begin{document}
\begin{description}[align=right]
\item[Rate of Reinforcement] Text that doesn't matter. The label is the same label that I need to use.
\end{description}

\end{document}

编辑(后续):我根据已接受的答案实施了解决方案,但现在我得到了这个。知道为什么现在标签前面有问号吗? 奇怪的问号

答案1

我猜你的意思是这样的。我只是把 3cm 作为标签宽度,但你也可以从 memoir 中检索边距的确切宽度。

\documentclass[12pt, letterpaper, oneside, draft]{memoir}
\usepackage{enumitem}
\usepackage{blindtext}

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

\begin{document}

\blindtext

\begin{description}[style=multiline,leftmargin=0pt,labelwidth=3cm,align=parright]
\item[Rate of Reinforcement] Text that doesn't matter. The label is
  the same label that I need to use. Make the line a little longer to
  show that it breaks nicely.
\item[Rate of Reinforcement] Text that doesn't matter. The label is
  the same label that I need to use. Make the line a little longer to
  show that it breaks nicely.
\item[Rate of Reinforcement] Short line to see it fail!
\item[Rate of Reinforcement] Text that doesn't matter. The label is
  the same label that I need to use. Make the line a little longer to
  show that it breaks nicely.
\end{description}

\blindtext

\end{document}

在此处输入图片描述

答案2

您可以替换\item,但您必须为每个描述环境重新执行此操作。

\documentclass{article}
\usepackage{enumitem}
\usepackage{ifoddpage}
\usepackage{showframe}

\setlist[itemize]{noitemsep, topsep=0pt}

\newcommand{\biglabel}[1]% #1 = label for \item
{\checkoddpage
  \bgroup% use local registers
  \ifoddpageoroneside% compute margin size
    \dimen0=\oddsidemargin
  \else
    \dimen0=\evensidemargin
  \fi
  \advance\dimen0 by 1in
  \settowidth{\dimen1}{\textbf{#1}}% compute label size
  \ifdim\dimen1>\dimen0
    \smash{\parbox[t]{\dimen0}{\raggedleft #1}}%
  \else
    #1
  \fi
\egroup}

\begin{document}
\begin{description}[align=right]
\item[\biglabel{Another Rate of Reinforcement}] Text that doesn't matter. The label is the same label that I need to use.
The question is what happens to the second line,
\end{description}

答案3

尝试以下操作。您可以尝试使用leftmargin和的值labelindent(为其指定一个负值以将其移至边距)。

\documentclass[12pt, letterpaper, oneside, draft]{memoir}
\usepackage{enumitem}

% itemize environment configuration
\setlist[itemize]{noitemsep, topsep=0pt}
\SetLabelAlign{parright}{\parbox[t]{\labelwidth}{\raggedleft#1}}


\begin{document}
\lipsum[1]
\begin{description}[style=multiline,leftmargin=1in,labelindent=-\leftmargin,align=parright]

\item[Rate of Reinforcement] Text that doesn't matter. The label is the same label that I need to use.
\item[Reinforcement] Text that doesn't matter. The label is the same label that I need to use.

\end{description}

\end{document}

代码输出

相关内容