我在用thmtools
\declaretheoremstyle
使用和创建示例环境\declaretheorem
。我还使用 键修改样式mdframed
,以创建框架、为示例环境的背景添加阴影并为其添加圆角。我还想格式化标题文本,即Example 1
在示例之前在标题下方放置一条彩色线,但我不知道如何执行此操作。我可以看到可以使用 \newmdenv 来创建示例环境,但我想坚持使用\declaretheoremstyle
和\declaretheorem
,因为我正在将其用于我所有其他环境。有人可以帮忙吗?
\documentclass[12pt,a4paper]{report}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}
\usepackage{thmtools}
% example style
\declaretheoremstyle[
headfont=\bfseries,
notebraces={[}{]},
bodyfont=\normalfont\itshape,
headpunct={},
postheadspace=\newline,
spacebelow=\parsep,
spaceabove=\parsep,
mdframed={
backgroundcolor=red!20,
linecolor=red!30,
innertopmargin=6pt,
roundcorner=5pt,
innerbottommargin=6pt,
skipbelow=\parsep,
skipbelow=\parsep }
]{myexamplestyle}
% example environment - thmtools
\declaretheorem[
style=myexamplestyle,
name=Example,
numberwithin=chapter
]{example}
\begin{document}
\begin{example}[Example 1]
something
\end{example}
\end{document}
答案1
像这样吗?
\documentclass[12pt,a4paper]{report}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{lipsum}% just to generate text for the example
% example style
\declaretheoremstyle[
headfont=\bfseries,
notebraces={[}{]},
bodyfont=\normalfont\itshape,
headpunct={},
postheadspace=\newline,
postheadhook={\textcolor{red}{\rule[.6ex]{\linewidth}{0.4pt}}\\},
spacebelow=\parsep,
spaceabove=\parsep,
mdframed={
backgroundcolor=red!20,
linecolor=red!30,
innertopmargin=6pt,
roundcorner=5pt,
innerbottommargin=6pt,
skipabove=\parsep,
skipbelow=\parsep }
]{myexamplestyle}
% example environment - thmtools
\declaretheorem[
style=myexamplestyle,
name=Example,
numberwithin=chapter
]{example}
\begin{document}
\chapter{Test}
\begin{example}[Additional text]
\lipsum[4]
\end{example}
\end{document}