以下代码产生所需的结果,如下所示:
\documentclass[letterpaper]{article}
\usepackage{xcolor}
\usepackage{amsmath,amssymb,calc,bbding}
\usepackage{enumitem}
\newlist{objective}{enumerate}{2}
\setlist[objective]{label=\protect\raisebox{-1pt}{\textcolor{blue!15}{\CheckmarkBold}}\hspace{-0.75\checklength}\arabic*}
\newlength{\checklength}
\settowidth{\checklength}{\CheckmarkBold}
\begin{document}
% Desired result.
\begin{objective}
\item First
\item Second
\end{objective}
% Not really a desired result.
{\large
\begin{objective}
\item First
\item Second
\end{objective}}
% Even worse.
{\huge
\begin{objective}
\item First
\item Second
\end{objective}}
\end{document}
如果您注意到,在第一级,一切似乎都很好,但随着字体大小的增加,就会出现字距调整的问题。如果枚举可以修复或缩放,可能会有很大帮助。
答案1
您实际上不需要知道复选标记的宽度。您可以简单地将复选标记叠加在一起\rlap
,稍微向左移动一点(相对于当前类型大小),因为复选标记比数字要宽一点。以下是实现此目的的列表项的定义:
\setlist[objective]{label=\protect\raisebox{-1pt}{\textcolor{blue!15}%
{\rlap{\kern-.3em\CheckmarkBold}}}\arabic*}
您可以省略此定义的所有代码\checklength
;其他内容无需更改。
编辑:要调整 2 位数字,必须检查计数器的数值。这有点棘手,因为它\setlist
会立即扩展其参数,必须抑制这一点才能测试计数器。(我定义了一个名称不是很新颖的测试计数器,但应该可以使用 Latex 中已有的临时计数器之一;我没有花时间去调查,因为解决扩展问题才是最重要的。)用下面的代码替换上面的代码将适用于两位数字;将其调整为两位以上的数字留给读者练习——原理应该很清楚。
\makeatletter
\newcount\xxtempcnt
\setlist[objective]{label=\protect\raisebox{-1pt}{\textcolor{blue!15}%
{\xxtempcnt=\@nameuse{c@\@listctr}%
\rlap{\noexpand\ifnum\xxtempcnt < 10 \kern-.3em
\noexpand\fi
\CheckmarkBold}}}\arabic*}
\makeatother
结果:
答案2
您正在设置\checklength
固定字体大小。相反,应该在使用当前字体大小之前完成此操作:
\documentclass[letterpaper]{article}
\usepackage{xcolor}
\usepackage{amsmath,amssymb,calc,bbding}
\usepackage{enumitem}
\newlist{objective}{enumerate}{2}
\setlist[objective]{label=%
\protect\raisebox{-1pt}{\textcolor{blue!15}{\CheckmarkBold}}%
\SetCheckLength
\hspace{-0.75\checklength}\arabic*}
\newlength{\checklength}
\settowidth{\checklength}{\CheckmarkBold}
\DeclareRobustCommand*{\SetCheckLength}{%
\settowidth{\checklength}{\CheckmarkBold}%
}
\begin{document}
% Desired result.
\begin{objective}
\item First
\item Second
\end{objective}
% Not really a desired result.
{\large
\begin{objective}
\item First
\item Second
\end{objective}}
% Even worse.
{\huge
\begin{objective}
\item First
\item Second
\end{objective}}
\end{document}
支持更多数字的不同版本
以下示例将复选标记设置在数字后面的背景中,而不占用额外空间:
\documentclass[letterpaper]{article}
\usepackage{xcolor}
\usepackage{amsmath,amssymb,calc,bbding}
\usepackage{enumitem}
\newlist{objective}{enumerate}{2}
\setlist[objective]{label=%
% \protect\raisebox{-1pt}{\textcolor{blue!15}{\CheckmarkBold}}%
\protect\CheckNum{\arabic*}%
}
\newcommand*{\CheckNum}[1]{%
\begingroup
\leavevmode
\sbox0{#1}%
\hbox to \wd0{%
\hss
\raisebox{-1pt}[0pt][0pt]{\textcolor{blue!15}{\CheckmarkBold}}%
\hss
}%
\llap{\box0}%
\endgroup
}
\begin{document}
% Desired result.
\begin{objective}
\item First
\item Second
\addtocounter{objectivei}{7}%
\item Tenth
\addtocounter{objectivei}{89}%
\item Hundredth
\end{objective}
% Not really a desired result.
{\large
\begin{objective}
\item First
\item Second
\addtocounter{objectivei}{7}%
\item Tenth
\addtocounter{objectivei}{89}%
\item Hundredth
\end{objective}}
% Even worse.
{\huge
\begin{objective}
\item First
\item Second
\addtocounter{objectivei}{7}%
\item Tenth
\addtocounter{objectivei}{89}%
\item Hundredth
\end{objective}}
\end{document}