我正在寻找一种方法来设计如图所示的定理这里。
如果我想在标题框中显示定理编号,但还想传递自定义定理名称以添加到该标题框,那么那里的代码就可以正常工作。可选参数似乎显示为 #1 的一部分,那么我该如何将其分开以便将其放在其他地方?
我目前正在使用的代码(来自上述同一链接)
\usepackage{graphicx,textpos, a4wide}
\usepackage{helvet, amssymb}
\usepackage{tikz}
\usetikzlibrary{shadows}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations}
\usepackage{framed}
\usepackage[framed, amsthm]{ntheorem}
\theoremclass{Theorem}
\theoremstyle{empty}
\newcommand{\thmbox}[1]{
\tikzstyle{thmbox} = [rectangle, rounded corners, draw=black, fill=gray!20, inner sep=15pt, drop shadow={fill=black, opacity=.5}]%
\tikzstyle{fancytitle} =[fill=white, text=black, rectangle, rounded corners, draw= black]%
\noindent%
\begin{tikzpicture}%
\node [thmbox] (box){%
\begin{minipage}{.91\textwidth}%
\textit{#1}%
\end{minipage}%
};%
\node[fancytitle, right=10pt] at (box.north west) {\textbf{Theorem \thetheorem}%
};%
\end{tikzpicture}}
\def\theoremframecommand{\thmbox}
\newshadedtheorem{theorem}{Theorem}
在正文中:
\begin{theorem}[abc]
Hello
\end{theorem}
答案1
根据这些评论,我创建了一种方法。
代码中最重要的部分是 的重新定义\mdfcreateextratikz
。包提供了此命令来将额外的材料放在某处。坐标O
和P
是内部使用的。在文件中,md-frame-1.mdf
您可以找到它们的含义。
\documentclass{article}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shadows,shadings}
\usepackage{lipsum}
\newcounter{theorem}
\renewcommand\thetheorem{Theorem~\arabic{theorem}}
\makeatletter
\mdf@dolist{\mdf@do@stringoption}{%
{theoremtitle=={}}%
}
\renewrobustcmd\mdfcreateextratikz{%
\node[anchor=west,rounded corners,draw,thick,shading=axis,left color=blue!20,xshift=1cm,minimum height=.7cm,minimum width=2cm] at (P-|O)
{~\mdf@frametitlefont{\thetheorem}%
\ifdefempty{\mdf@theoremtitle}%
{~}%
{:~\mdf@theoremtitle~}%
};
}
\makeatother
\mdfdefinestyle{theoremstyle}{%
outerlinewidth=1pt,
innerlinewidth=0pt,
roundcorner=2pt,
linecolor=black,
shadow=true,
tikzsetting={shading=axis,top color=gray!20},
innertopmargin=1.2\baselineskip,
skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
needspace=3\baselineskip,
frametitlefont=\sffamily\bfseries,
settings={\global\stepcounter{theorem}},
}
\newenvironment{theorem}[1][]
{\begin{mdframed}[style=theoremstyle,theoremtitle={#1}]\relax}{\end{mdframed}}
\begin{document}
\begin{theorem}
\lipsum[1]
\end{theorem}
\begin{theorem}[Title of the Theorem]
\lipsum[1]
\end{theorem}
\end{document}
其结果是: