在我的文档中,我希望提供带有解决方案的示例问题。我目前使用amsthm
以下包执行此操作:
\documentclass{article}
\usepackage{lmodern}
\usepackage{amssymb,amsthm}
\newtheoremstyle{examplesty} % Name
{} % Above skip
{} % Below skip
{\upshape} % Body font
{} % Indent
{\bfseries} % Head font
{} % Head body punct
{1em} % Space after head
{} % Heading
% Examples rejig the theorem environment
\theoremstyle{examplesty}
\newtheorem{example}{Example}[section]
% Solutions use a modified proof environment
\newenvironment{solution}
{\let\oldqedsymbol=\qedsymbol
\renewcommand{\qedsymbol}{$\blacktriangleleft$}
\begin{proof}[\bfseries\upshape Solution]}
{\end{proof}
\renewcommand{\qedsymbol}{\oldqedsymbol}}
\begin{document}
\section{Test Section}
\begin{example} This is an example problem \end{example}
\begin{solution} This is a solution to an example problem. \end{solution}
\end{document}
我的问题是,示例和解决方案的标题和正文之间的间距不同。此外,解决方案后面有一个句号,这看起来很奇怪。是否可以纠正这些问题,还是我试图用旧鞋敲钉子?
答案1
您可以使用thm工具前端可以轻松与之交互(例如)amsthm
;这将很容易为您提供间距的一致性。以下是显示您的定义将如何显示的示例:
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
numberwithin=section
]{exstyle}
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
headpunct={},
qed=$\blacktriangleleft$,
numbered=no
]{solstyle}
\declaretheorem[style=exstyle]{example}
\declaretheorem[style=solstyle]{solution}
\begin{document}
\section{Test section}
text text text
\begin{example}
text text text
\end{example}
text text text
text text text
\begin{solution}
text text text
\end{solution}
text text text
\end{document}
答案2
删除句点:
\makeatletter
\newenvironment{solution}
{\let\oldqedsymbol=\qedsymbol%
\def\@addpunct##1{}%
\renewcommand{\qedsymbol}{$\blacktriangleleft$}%
\begin{proof}[\bfseries\upshape Solution]}%
{\end{proof}%
\renewcommand{\qedsymbol}{\oldqedsymbol}}
\makeatother
要修改长度,可以使用奇数解决方案:
\def\@addpunct##1{\hspace*{1em}}