\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}
选自:http://tex.stackexchange.com/questions/11098/nice-formatting-for-theorems
发表评论 取消回复