LaTeX 的列表内容与页面的左右间距是通过 \parshape 实现的。因此解决这个问题的想法是,量取每一个编号的宽度,动态地调整 \parshape 的缩进。可以通过 enumitem 包的 \SetLabelAlign 定义一个特殊的对齐方式来实现。
\documentclass{article}
\usepackage{enumitem}
\makeatletter
%% 定义对齐方式 hang
\SetLabelAlign{hang}{%
#1%
\aftergroup\adjustparshapeindent}
%% 编号 #1 会通过 \sbox 存到 \@tempboxa 中,为避免全局设置,
%% 需要用 \aftergroup 跳到盒子外部来设置
\newcommand*\adjustparshapeindent{%
\@ifnextchar\egroup
{\aftergroup\adjustparshapeindent}
{\adjustparshapeindent@auxi}}
\newcommand*\adjustparshapeindent@auxi{%
\unless\ifdim\wd\@tempboxa=\labelwidth
\adjustparshapeindent@auxii
\fi}
%% 调整 \parshape 的缩进
\newcommand*\adjustparshapeindent@auxii{%
\dimen@ = \dimexpr\wd\@tempboxa-\labelwidth\relax
\labelwidth = \wd\@tempboxa
\advance\linewidth -\dimen@
\advance\leftmargin \dimen@
\advance\@totalleftmargin \dimen@
\parshape \@ne \@totalleftmargin \linewidth}
\makeatother
\begin{document}
\begin{enumerate}[align=hang, start=9]
\item test\\test
\item test\\test
\end{enumerate}
\end{document}
效果图:
选自:https://www.zhihu.com/question/53242822/answer/134167664