有时我们会希望在文本的同一行开始一个列表环境,而非是使用默认的在下一行开始。同时,我们会希望列表环境的标签仍旧在垂直方向上对齐。 LaTeX 提供的 itemize 环境和 enumerate 环境事实上都是 list 环境的一种,但 itemize 和 enumerate 不允许修改\labelsep等距离。因此,要达到我们的目的,我们要么使用原始的 list 环境,要么使用 description 环境——它允许修改这些距离。 代码:

\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum} % just for the example

\newlength{\jeroenlen}
\newenvironment{example}
{\settowidth{\jeroenlen}{\textbf{Example:}}%
\begin{description}[leftmargin=\jeroenlen,labelwidth=0pt,labelsep=0pt]
\item[\textbf{Example:}]%
\begin{itemize}[leftmargin=1.5em,labelsep=.5em]}
{\end{itemize}\end{description}}

\begin{document}
\lipsum[2]
\begin{example}
\item Such and such
\item So and so
\item Enough
\end{example}
\lipsum[3]
\end{document}
效果: xbCIc
Sometimes, we hope that an itemize environment could start at the same line of certain text, rather than start at the next line as the default does. Moreover, the labels should be vertically aligned. Theitemizeandenumerateenvironment provided by the standard LaTeX are both descendant oflistenvironment, however, length, such as\labelsep, are prevented from modifying. Thus, we have two choices: usinglistor usingdescriptionwhose length chould be modified. Code:
\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum} % just for the example

\newlength{\jeroenlen}
\newenvironment{example}
{\settowidth{\jeroenlen}{\textbf{Example:}}%
\begin{description}[leftmargin=\jeroenlen,labelwidth=0pt,labelsep=0pt]
\item[\textbf{Example:}]%
\begin{itemize}[leftmargin=1.5em,labelsep=.5em]}
{\end{itemize}\end{description}}

\begin{document}
\lipsum[2]
\begin{example}
\item Such and such
\item So and so
\item Enough
\end{example}
\lipsum[3]
\end{document}
And the output: xbCIc1选自:http://liam0205.me/LaTeX-How-to-start-itemize-on-same-line-as-text/

点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部