![示例开始和结束前的一行](https://linux22.com/image/343586/%E7%A4%BA%E4%BE%8B%E5%BC%80%E5%A7%8B%E5%92%8C%E7%BB%93%E6%9D%9F%E5%89%8D%E7%9A%84%E4%B8%80%E8%A1%8C.png)
我有这个示例风格:
\newtheoremstyle{example}{}{}{}{}{\bfseries}{\smallskip}{\newline}{}
\theoremstyle{example}
\newtheorem{example}{Example}
我想在“示例”标题之前和示例结束之后添加一条细小而粗的浅绿色线条。可以这样做吗?
答案1
这是有可能的。比如
\documentclass{article}
\usepackage{amsthm}
\newtheoremstyle{example}{}{}{}{}{\bfseries}{\smallskip}{\newline}{}
\theoremstyle{example}
\newtheorem{example}{Example}
%%
\usepackage[nopar]{lipsum}
\usepackage{xcolor}
%%
\newenvironment{greenexample}{%
\par\noindent{\color{green}\hrule height 1pt}\hfill\vspace*{-\baselineskip}
\begin{example}%
}{%
\strut{\color{green}\hrule height 1pt\hfill}
\end{example}
}
\begin{document}
\lipsum[2]
\begin{example}[Test]
As an example \textit{e.g.} can be used.
\end{example}
\lipsum[2]
\begin{greenexample}[Test]
As an example \textit{e.g.} can be used.
\end{greenexample}
\lipsum[2]
\end{document}
答案2
一个简单的解决方案thmtools
,它与配合使用amsthm
:
\documentclass{article}
\usepackage{amsthm, thmtools}
\newtheoremstyle{example}{}{}{}{}{\bfseries}{\smallskip}{\newline}{}
%
\declaretheorem[%
style=example,%
preheadhook={\bigskip{\color{DarkSeaGreen3}\hrule height 0.8pt\vspace{-1ex}}},%
postfoothook={\vspace{-0.8ex}{\color{DarkSeaGreen3}\hrule height 0.8pt}\bigskip}]%
{Example}%
\usepackage{lipsum, graphicx}
\usepackage[x11names]{xcolor}
\begin{document}
\lipsum[2]
%
\begin{Example}[Test]
As an example \textit{e.g.} can be used by Latin lovers ; o)
\begin{center}
\includegraphics[scale=0.5]{pepe-le-pew2}
\end{center}
\end{Example}
%
\lipsum[11]
\end{document}