我一直在使用下面的代码来为我的定理(和其他类似定理的环境)创建悬垂。
\documentclass{article}
\usepackage{amsthm}
\usepackage{mdframed}
\newlength{\marginlabelsep}\setlength{\marginlabelsep}{1em}
\newtheoremstyle{thmoverhang} %% Name
{}
{}
{\sffamily}
{}
{\bfseries}
{}
{0pt}
{\vtop to 0pt{\hbox to -\marginlabelsep{\hss\thmname{#1}}
\hbox to -\marginlabelsep{\hss\thmnumber{#2}}}\thmnote{#3\\}%
}
\theoremstyle{thmoverhang}
\newtheorem{thm}{Theorem}
(事实上,它是由本网站的另一位用户贡献的,但这不是重点。)我最近想使用包在我认为重要的定理周围添加一个框\mdframed
,就像这样
\newenvironment{fthm}{\begin{mdframed}\begin{thm}}{\end{thm}\end{mdframed}\vspace{-0.3cm}
但这会导致一个问题,即盒子里没有定理和计数器(见下图)。我怎样才能使框更大,以同时包含定理描述和定理标题和计数器?此外,是否可以抬起框的上边框;它似乎太低了,框内文本的顶部和底部填充似乎不相等。任何意见都值得赞赏!
梅威瑟:
\documentclass{article}
\usepackage{amsthm}
\usepackage{mdframed}
\usepackage{lipsum}
\newlength{\marginlabelsep}\setlength{\marginlabelsep}{1em}
\newtheoremstyle{thmoverhang} %% Name
{}
{}
{\sffamily}
{}
{\bfseries}
{}
{0pt}
{\vtop to 0pt{\hbox to -\marginlabelsep{\hss\thmname{#1}}
\hbox to -\marginlabelsep{\hss\thmnumber{#2}}}\thmnote{#3\\}%
}
\theoremstyle{thmoverhang}
\newtheorem{thm}{Theorem}
\renewcommand{\familydefault}{\sfdefault}
\newenvironment{fthm}{ \begin{mdframed}\begin{thm} }{ \end{thm}\end{mdframed}\vspace{-0.3cm} }
\setlength{\parskip}{1em}
\begin{document}
\begin{fthm}
Theorem Description Theorem Description Theorem Description Theorem Description
\end{fthm}
\lipsum[1]
\end{document}
答案1
和tcolorbox
:
\documentclass{article}
\usepackage{lipsum}%<--- for testing purpose only
\usepackage[most]{tcolorbox}
\newcounter{myth}
\tcbset{
commonopt/.style={
enhanced,
enhanced jigsaw,
breakable,
sharp corners,
left=80pt,
fontupper=\itshape,
opacityback=0,
boxrule=1pt,
text width=\linewidth,
oversize,
},
}
\tikzset{
titlenode/.style={
anchor=north west,
font=\bfseries,
text width=66pt,
inner sep=3mm+1pt,
align=right
}
}
\newtcolorbox[use counter=myth]{thm}[2][]{%
commonopt,
opacityframe=0,
overlay={\node[titlenode] at (frame.north west) {\vphantom{p}Theorem~\themyth\ #2};},
#1
}
\newtcolorbox[use counter=myth]{fthm}[2][]{%
commonopt,
before skip=14pt plus 2pt minus 2pt,
after skip=14pt plus 2pt minus 2pt,
overlay={\node[titlenode] at (frame.north west) {\vphantom{p}Theorem~\themyth\ #2};},
#1
}
\begin{document}
\lipsum[1]
Theorem \ref{th:nofnot} is with no frame and no title, only with theorem number.
\begin{thm}[label=th:nofnot]{}
Theorem Description Theorem Description Theorem Description Theorem Description
\end{thm}
Theorem \ref{th:nofyest} is with no frame but with title, other than number.
\begin{thm}[label=th:nofyest]{(Pythagoras)}
Theorem Description Theorem Description Theorem Description Theorem Description
\end{thm}
Theorem \ref{th:yesfnot} is with frame but without title, only number.
\begin{fthm}[label=th:yesfnot]{}
Theorem Description Theorem Description Theorem Description Theorem Description
\end{fthm}
Theorem \ref{th:yesfyest} is with frame, title and number.
\begin{fthm}[label=th:yesfyest]{(Pythagoras)}
Theorem Description Theorem Description Theorem Description Theorem Description
\end{fthm}
\lipsum[1]
\end{document}