我正在尝试创建如下所示的列表:
我已尝试 \renewcommand{\labelenumi}{...},但它不允许我输入除符号和字符之外的任何内容(例如,我似乎无法在其中使 \fbox 或 \adjustbox 正常工作)。
\documentclass[11pt]{article}
\usepackage{xcolor}
\usepackage{adjustbox}
\renewcommand{\labelenumi}{\adjustbox{cfbox=darkgray 1pt 3pt, bgcolor=darkgray}{\color{white} \theenumi}}
\renewcommand{\labelenumii}{\Alph{enumii})}
\begin{document}
\begin{enumerate}
\item Which choice...
\begin{enumerate}
\item Answer A
\item Answer B
\item Answer C
\item Answer D
\end{enumerate}
\end{enumerate}
\end{document}
答案1
这可以通过enumitem
和TikZ
。我定义了一个新的专用列表fancyenum
(我将其定义为两个嵌套级别,但如果需要,可以增加)产生了所需的结果:
代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{enumitem}
\newlist{fancyenum}{enumerate}{2}
\setlist[fancyenum,1]{
leftmargin=12pt,
labelsep=10pt,
label={\protect\begin{tikzpicture}[]
\protect\node[overlay,text width=\textwidth,fill=gray!20,anchor=west,inner sep=0pt,minimum height=2em] (bg) {};
\protect\node[overlay,anchor=west,minimum height=2em,inner sep=0pt,fill=black,align=center,text width=2em,text=white,font=\bfseries] at (bg.west) {\arabic*};
\protect\node {\rule[5em]{0pt}{0pt}};
\protect\end{tikzpicture}}
}
\setlist[fancyenum,2]{label=\Alph*),topsep=0pt,leftmargin=22pt}
\begin{document}
\sffamily
\begin{fancyenum}
\item Some test text
\begin{fancyenum}
\item First
\item Second
\item Third
\end{fancyenum}
\item Some test text
\begin{fancyenum}
\item First
\item Second
\item Third
\end{fancyenum}
\item Some test text
\begin{fancyenum}
\item First
\item Second
\item Third
\end{fancyenum}
\end{fancyenum}
\end{document}
答案2
enumitem
仅使用、eqparbox
((以跟踪标签宽度)和的解决方案xcolor
。我试图尽可能接近OP在他的帖子中的图像。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{eqparbox}
\newlist{myenum}{enumerate}{2}
\setlist[myenum, 1]%
{label =\eqparbox[t][\baselineskip]{N}{\colorbox{black}{\,\arabic*\,}} \hskip-0.333em{\color{lightgray!50!} \rule[-0.25\baselineskip]{\dimexpr\textwidth-\eqboxwidth{N}-2\parindent\relax}{\dimexpr\baselineskip+0.4pt\relax} \rule[-3ex]{0pt}{3ex}},
align=left,
font=\bfseries\color{white},
wide=0pt,
leftmargin=\eqboxwidth{N},itemsep =1.5\baselineskip}%
\setlist[myenum, 2]{label=\Alph*),leftmargin=*, topsep=0pt}
\begin{document}
\begin{myenum}[start=7]%
\item The main purpose of the first paragraph is to
\begin{myenum}
\item describe a culture.
\item criticize a tradition.
\item question a suggestion.
\item analyze a reaction.
\end{myenum}
\item As used in line 2, “form” most nearly means
\begin{myenum}
\item appearance.
\item custom.
\item structure.
\item nature.
\end{myenum}
\end{myenum}
\end{document}