我希望我能更具体一些,但由于我不了解正在发生的所有潜在事情,我的问题必须含糊其辞(因此标题很尴尬,一旦我了解细节,我会对其进行编辑以使其更具体),抱歉。
问题:为什么它\settowidth{\hangindent}{some text}
不能在我的环境中工作lemma
(我认为,它是使用many
来自的选项创建的tcolorbox
)?
(我曾尝试调整\parindent
,以修复我使用的其他 tcolorboxes 中的一些缩进问题,但显然在这里不行。)
提前致谢!
梅威瑟:
\documentclass{report}
% Packages used
\usepackage[many]{tcolorbox}
% Counter (probably unrelated)
\newcounter{lemmacounter}[chapter]
\def\thelemmacounter{\thechapter.\arabic{lemmacounter}}
% Where the problem probably lies
% lemma command for lemma environment using tcolorbox (somehow, I'm not really sure how this is working), with optional "name" argument
\DeclareDocumentCommand \lemma {o} {%
\IfNoValueTF {#1} {%
\noindent\refstepcounter{lemmacounter}\colorbox{black!10}{\textbf{L-\thelemmacounter}}\itshape %
\settowidth{\hangindent}{L-00 }\hangafter=1 % Why does this not work?
}{%
\noindent\refstepcounter{lemmacounter}\colorbox{black!10}{\textbf{L-\thelemmacounter}}\textbf{ (#1).}\itshape
\settowidth{\hangindent}{L-00 }\hangafter=1 % Why does this not work?
}%
}
\begin{document}
\begin{lemma}[Some Lemma]
Some text some text some text some text some text some text some text some text some text some text some text.
\end{lemma}
\end{document}
答案1
您可以通过稍微改变您的定义来满足您的要求,如下所示:
\newenvironment{lemma}[1][\empty]{\begingroup
\if!#1!\noindent\refstepcounter{lemmacounter}\colorbox{black!10}{\textbf{L-\thelemmacounter}}\itshape
\else%
\noindent\refstepcounter{lemmacounter}\colorbox{black!10}{\textbf{L-\thelemmacounter}}\textbf{ (#1)}\itshape\fi
\settowidth{\hangindent}{L-00 }\hangafter=1%
}{\par%this does the trick for the hangindent
\endgroup}