我正在写一篇包含一些定理的文章,我想对这些定理使用特殊的格式 - 我的想法是在定理的一侧放一条灰线。你能告诉我怎么做吗?
此外,如果您对定理等的良好格式有其他想法,我很乐意听听。
答案1
答案2
我最近请求一些关于定理修饰的帮助与定理环境一致的定理装饰。我想要一些能够与常规文本区分开的东西(以使定理脱颖而出),但不要太多。此外,环境应该很容易跨页面中断,而不会造成问题(带有孤立/寡妇装饰)或在视觉上“损坏”(如截断的框架)。经过一些修改后,结果如下:
\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{ifmtarg}% http://ctan.org/pkg/ifmtarg
\usepackage{xifthen}% http://ctan.org/pkg/xifthen
\usepackage{environ}% http://ctan.org/pkg/environ
\usepackage{multido}% http://ctan.org/pkg/multido
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\makeatletter%
\newcommand{\theoremhang}{% top theorem decoration
\begingroup%
\setlength{\unitlength}{.005\linewidth}% \linewidth/200
\begin{picture}(0,0)(1.5,0)%
\linethickness{0.45pt} \color{black!50}%
\put(-3,2){\line(1,0){206}}% Top line
\multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
\color{black!\iB}%
\put(-3,\iA){\line(0,-1){1}}% Top left hang
\put(203,\iA){\line(0,-1){1}}% Top right hang
}%
\end{picture}%
\endgroup%
}%
\newcommand{\theoremhung}{% bottom theorem decoration
\nobreak
\begingroup%
\setlength{\unitlength}{.005\linewidth}% \linewidth/200
\begin{picture}(0,0)(1.5,0)%
\linethickness{0.45pt} \color{black!50}%
\put(-3,0){\line(1,0){206}}% Bottom line
\multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
\color{black!\iB}%
\put(-3,\iA){\line(0,1){1}}% Bottom left hang
\put(203,\iA){\line(0,1){1}}% Bottom right hang
}%
\end{picture}%
\endgroup%
}%
\newcounter{theorem}
\renewcommand{\thetheorem}{\arabic{theorem}}
\NewEnviron{theorem}[1][]{%
\par\noindent\theoremhang\par\nobreak\noindent%\addvspace{-.5ex}
\refstepcounter{theorem}\postdisplaypenalty=10000 %
{\sffamily\bfseries\upshape Theorem \thetheorem\@ifnotmtarg{#1}{\ (#1)}}\ \ \itshape\ignorespaces%
\BODY % Typeset theorem body/content
\par\addvspace{-1ex}\nobreak\noindent\theoremhung\par\addvspace{.4ex}%
}
\makeatother
\begin{document}
\lipsum[1]
\begin{theorem}[Special theorem]
\lipsum[2]
\end{theorem}
And then there is also
\begin{theorem}[Short theorem]
This is just a short theorem description.
\end{theorem}
\lipsum[3]
\end{document}
答案3
不完全是你想要的,但这是一个例子唐纳德·阿瑟诺使用框架包:
\documentclass{article}
\usepackage{color,amsmath}
\usepackage{framed}
\makeatletter
\newdimen\errorsize \errorsize=0.2pt
% Frame with a label at top
\newcommand\LabFrame[2]{%
\fboxrule=\FrameRule
\fboxsep=-\errorsize
\textcolor{FrameColor}{%
\fbox{%
\vbox{\nobreak
\advance\FrameSep\errorsize
\begingroup
\advance\baselineskip\FrameSep
\hrule height \baselineskip
\nobreak
\vskip-\baselineskip
\endgroup
\vskip 0.5\FrameSep
\hbox{\hskip\FrameSep \strut
\textcolor{TitleColor}{\textbf{#1}}}%
\nobreak \nointerlineskip
\vskip 1.3\FrameSep
\hbox{\hskip\FrameSep
{\normalcolor#2}%
\hskip\FrameSep}%
\vskip\FrameSep
}}%
}}
\definecolor{FrameColor}{rgb}{0.25,0.25,1.0}
\definecolor{TitleColor}{rgb}{1.0,1.0,1.0}
\newenvironment{contlabelframe}[2][\Frame@Lab\ (cont.)]{%
% Optional continuation label defaults to the first label plus
\def\Frame@Lab{#2}%
\def\FrameCommand{\LabFrame{#2}}%
\def\FirstFrameCommand{\LabFrame{#2}}%
\def\MidFrameCommand{\LabFrame{#1}}%
\def\LastFrameCommand{\LabFrame{#1}}%
\MakeFramed{\advance\hsize-\width \FrameRestore}
}{\endMakeFramed}
\newcounter{theorem}
\newenvironment{theorem}[1]{%
\par
\refstepcounter{theorem}%
\begin{contlabelframe}{Theorem \thetheorem:\quad #1}
\noindent\ignorespaces}
{\end{contlabelframe}}
\makeatother
\begin{document}
\begin{theorem}{Pythagoras}
This is a theorem
\end{theorem}
\end{document}
您将获得以下内容:
答案4
2011 年下半年,Thomas F. Sturm 发布了一个名为tcolorbox
来创建您想要的特殊效果。这样,您就不需要像其他答案的示例那样在序言中创建如此大的开销。
这里我给你一个 MWE,但有关更多详细信息,请查看包装手册:
\documentclass{article}
\usepackage[listings]{tcolorbox}
\tcbuselibrary{listings,theorems}
\newtcbtheorem[number within=section]{mytheo}{My Theorem}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}
\begin{document}
\begin{mytheo}{This is the theorem title}{label_of_the_theorem}
This is the text of the theorem. The counter is automatically assigned and,
in this example, prefixed with the section number. This theorem is numbered with
\ref{th:label_of_the_theorem} and is given on page \pageref{th:label_of_the_theorem}.
\end{mytheo}
The theorem enumerator adds the number of the section as indicated in the preamble.
\end{document}