对于我的论文,我想把定理放在一个特殊的框中,为此我创建了一个命令,\specialbox
它利用\stackinset
命令,这样我就得到了定理周围的部分框架。它的设计归功于 Steven B. Segletes,我发现了这个设计这里。下面我附上了一张说明设计和问题的图片(见下文),下面我还包含了 MWE。
问题:对于这个设计,我已经使用了\stackinset
四次。如下图所示,我们从定理 I 和方程 (1) 转到定理 XVII 和方程 (17),即两者都增加了 16。我认为这是因为每次\stackinset
使用时,计数器都会不必要地增加,并且在四次的情况下\stackinset
,计数器增加了 2^4 = 16。显然,这不是我想要的。有人知道解决这个问题的方法吗?
\documentclass[10pt,a4paper]{article}
%%% Load packages
\usepackage{stackengine}
\usepackage{amsmath}
%%% Define special box
% \specialbox{<rule width>}{<rule length hori>}{<rule length vert>}{<distance from text>}{<text>}
\newcommand{\specialbox}[5]{%
\stackinset{l}{}{t}{}{ \rule{#2}{#1} }{%
\stackinset{l}{}{t}{}{ \rule{#1}{#3} }{%
\stackinset{r}{-#1-#4}{b}{}{ \rule{#2}{#1} }{%
\stackinset{r}{-#1-#4}{b}{-#1-#4}{ \rule{#1}{#3} }{%
\hspace{\dimexpr #1+#4} \parbox{\dimexpr\textwidth-#4-#4-#1-#1}{
\vspace{\dimexpr #1+#4} #5}}}}}}
%%% Define counter
\newcounter{myThm}
\setcounter{myThm}{0}
\renewcommand*{\themyThm}{\Roman{myThm}}
\newcommand{\mythm}{ \refstepcounter{myThm} {\bfseries Theorem \themyThm.} }
\begin{document}
\specialbox{1.5pt}{35pt}{35pt}{10pt}{%
\mythm \\
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.
\begin{align}\label{eq}
\dot{x}(t) = f\big( t,x(t) \big)
\end{align}
Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt.
}
\vspace{30pt}
\specialbox{1.5pt}{35pt}{35pt}{10pt}{%
\mythm \\
Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus.
\begin{align}\label{eq}
\dot{y}(t) = g\big( t,y(t) \big)
\end{align}
Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
}
\end{document}
答案1
在 的定义中,在调用 s 之前\specialbox
将参数保存到存储中,现在将其应用于存储(名为)而不是原始参数本身。\parbox
\stackinset
\parbox
\tmpbox
\documentclass[10pt,a4paper]{article}
%%% Load packages
\usepackage{stackengine}
\usepackage{amsmath}
%%% Define special box
% \specialbox{<rule width>}{<rule length hori>}{<rule length vert>}{<distance from text>}{<text>}
\newcommand{\specialbox}[5]{%
\savestack\tmpbox{\parbox{\dimexpr\textwidth-#4-#4-#1-#1}{%
\vspace{\dimexpr #1+#4} #5}}
\stackinset{l}{}{t}{}{ \rule{#2}{#1} }{%
\stackinset{l}{}{t}{}{ \rule{#1}{#3} }{%
\stackinset{r}{-#1-#4}{b}{}{ \rule{#2}{#1} }{%
\stackinset{r}{-#1-#4}{b}{-#1-#4}{ \rule{#1}{#3} }{%
\hspace{\dimexpr #1+#4} \tmpbox}}}}}
%%% Define counter
\newcounter{myThm}
\setcounter{myThm}{0}
\renewcommand*{\themyThm}{\Roman{myThm}}
\newcommand{\mythm}{ \refstepcounter{myThm} {\bfseries Theorem \themyThm.} }
\begin{document}
\specialbox{1.5pt}{35pt}{35pt}{10pt}{%
\mythm \\
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.
\begin{align}\label{eq}
\dot{x}(t) = f\big( t,x(t) \big)
\end{align}
Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt.
}
\vspace{30pt}
\specialbox{1.5pt}{35pt}{35pt}{10pt}{%
\mythm \\
Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus.
\begin{align}\label{eq}
\dot{y}(t) = g\big( t,y(t) \big)
\end{align}
Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
}
\end{document}