我想在嵌套的枚举环境中插入一些没有左边距的文本块。
在下面的 MWE 中,这意味着我希望三个蓝框部分具有完整的文本宽度。
\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage[shortlabels]{enumitem}
\newenvironment{answer}
{\begin{mdframed}[
backgroundcolor = blue!15,
innerleftmargin = 2mm,
innerrightmargin = 2mm,
innertopmargin = 2mm,
needspace = 2cm,
topline = false,
bottomline = false,
leftline = false,
rightline = false,
nobreak = false,
fontcolor = blue!70!black
]}
{\end{mdframed}}
% For itemize
\setlist[itemize,1]{$\bullet$, leftmargin=1.5em, labelsep=0.5em}
\setlist[itemize,2]{$\rhd$}
% For enumerate level 1
\setlist[enumerate, 1]
{1.,
leftmargin = 2em,
itemindent = 0pt,
labelwidth = 2em,
labelsep = 0pt,
font = \bfseries,
align = left,
itemsep = 1.5mm,
ref = \mbox{\textup{\textbf{\arabic*.}}}}
% For enumerate level 2
\setlist[enumerate, 2]
{(a),
itemindent = 0pt,
labelwidth = 6.75mm,
align = left,
itemsep = 0.5mm,
leftmargin = 6.5mm,
ref=\mbox{\textup{\textbf{\theenumi{}}\hspace{1pt}(\alph*)}}}
% For enumerate level 3
\setlist[enumerate, 3]
{(i),
leftmargin = 6mm,
itemindent = 0pt,
labelsep = 1.5mm,
align = right,
itemsep = 0.25mm,
ref=\mbox{\textup{\theenumii\hspace{1pt}(\roman*)}}}
\begin{document}
\begin{enumerate}
\item
These are questions.
\begin{enumerate}
\item
These are sub questions.
\begin{enumerate}
\item
These are sub sub questions.
\begin{answer}
This is the answer.
\end{answer}
\end{enumerate}
\item This is another sub question.
\begin{answer}
This is the answer.
\end{answer}
\end{enumerate}
\item This is another question
\begin{answer}
This is the answer.
\end{answer}
\end{enumerate}
\end{document}
我希望输出更像这样:
感谢您的帮助。
答案1
\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage[shortlabels]{enumitem}
\makeatletter
\newenvironment{answer}
{\begin{mdframed}[
backgroundcolor = blue!15,
leftmargin=-\@totalleftmargin
innerleftmargin = 2mm,
innerrightmargin = 2mm,
innertopmargin = 2mm,
needspace = 2cm,
topline = false,
bottomline = false,
leftline = false,
rightline = false,
nobreak = false,
fontcolor = blue!70!black
]}
{\end{mdframed}}
\makeatother
% For itemize
\setlist[itemize,1]{$\bullet$, leftmargin=1.5em, labelsep=0.5em}
\setlist[itemize,2]{$\rhd$}
% For enumerate level 1
\setlist[enumerate, 1]
{1.,
leftmargin = 2em,
itemindent = 0pt,
labelwidth = 2em,
labelsep = 0pt,
font = \bfseries,
align = left,
itemsep = 1.5mm,
ref = \mbox{\textup{\textbf{\arabic*.}}}}
% For enumerate level 2
\setlist[enumerate, 2]
{(a),
itemindent = 0pt,
labelwidth = 6.75mm,
align = left,
itemsep = 0.5mm,
leftmargin = 6.5mm,
ref=\mbox{\textup{\textbf{\theenumi{}}\hspace{1pt}(\alph*)}}}
% For enumerate level 3
\setlist[enumerate, 3]
{(i),
leftmargin = 6mm,
itemindent = 0pt,
labelsep = 1.5mm,
align = right,
itemsep = 0.25mm,
ref=\mbox{\textup{\theenumii\hspace{1pt}(\roman*)}}}
\begin{document}
\begin{enumerate}
\item
These are questions.
\begin{enumerate}
\item
These are sub questions.
\begin{enumerate}
\item
These are sub sub questions.
\begin{answer}
This is the answer.
\end{answer}
\end{enumerate}
\item This is another sub question.
\begin{answer}
This is the answer.
\end{answer}
\end{enumerate}
\item This is another question
\begin{answer}
This is the answer.
\end{answer}
\end{enumerate}
\end{document}