请教各位大佬,如何实现列表环境的横向的各种宽度自动化?

发布于 2021-04-08 20:30:16

请教各位大佬,如何根据不同的标签宽度,自动改变横向的各种宽度?虽然可以逐一设置labelwidth,leftmargin之类的参数,但总觉得不方便,有没有自动调整的方法?
也就是说,labelsep设为0,labelwidth根据标签宽度自动设置,同时leftmargin也自动设置,从而到达悬挂缩进。

  \documentclass{ctexart}
  \usepackage{enumitem}
  \setenumerate{itemsep=0pt,partopsep=0pt,
  parsep=\parskip,topsep=0pt,
  labelwidth=*,align=left}

  \begin{document}
  \begin{enumerate}
  \item 文字文字文字文字文字文字文字文字文字文字文字文字文字文字文
  文字文字文字文字文字文字文字文字文字文字文字文字文字文字文
  \item[标签标签]测试测试测试测试测试测试测试测试测试测试
   试测试测试测试测试测试测试
  \end{enumerate}
  \end{document}

974187949fcecda7bba4d9125b19aa5a.png
再补充说明一下,我想要的效果是这样的
WechatIMG114.jpeg
也就是说,根据标签的宽度,自动设置悬挂缩进。

查看更多

关注者
0
被浏览
1.1k
2 个回答
如果您有什么不同意见,您是对的,我是错的。
这家伙很懒,什么也没写!

labelwidth 调大点不就好了

LaTeXStudio
LaTeXStudio 2021-04-08
这家伙很懒,什么也没写!

我很早以前写的文章可以看看 http://blog.sina.com.cn/s/blog_5e16f1770100jw8j.html (description列表不得不说的用法)
解决方案:
(1)使用mdwlist宏包,较为简便

\usepackage{mdwlist}
\begin{basedescript}{\desclabelstyle{\pushlabel}\desclabelwidth{10em}}
\item[Short]  This is a shorter item label, and some text that talks about it.
  The text is wrapped into a paragraph, with successive lines indented.

  The another paragraph within one item.
\item[Rather longer label] This is a longer item label.  As you can see, the
  text is not started a specified distance in -- unlike with other lists -- but
  is spaced a fixed distance from the end of the label.
\end{basedescript}

结果图:

image.png

(2)利用list环境定义自己的描述环境如下:

\usepackage{calc}
\newenvironment{altDescription}[1]
{\begin{list}{}%
{\renewcommand\makelabel[1]{\textsf{##1:}\hfil}%
\settowidth\labelwidth{\makelabel{#1}}%
\setlength\leftmargin{\labelwidth+\labelsep}}}%
{\end{list}}
\begin{altDescription}{Return values}
\item[Description]
Returns from a function. If issued at top level,
the interpreter simply terminates, just as if end
of input had been reached.
\item[Errors]
None.
\item[Return values]
Any arguments in effect are passed back to the
caller.
\end{altDescription}

需要自己提供最宽单词的参数。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览