我已经尝试过以下代码,
\documentclass{article}
\usepackage{amsthm,amssymb,xcolor}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}
\begin{document}
\begin{color}{blue}{\begin{thm}\begin{color}{red}{The theorem.}\end{thm}}\end{color}
\end{document}
但它不起作用。所以我的问题如下,
- 我该如何解决这个问题?例如,以下代码是什么,
标题将呈现蓝色,定理主体将呈现红色。
book
如果文档类是或,则相同的代码是什么memoir
?
答案1
最简单的方法是使用thmtools
界面。
\documentclass{article}
\usepackage{amsthm,thmtools,xcolor}
\declaretheoremstyle[
headfont=\color{blue}\normalfont\bfseries,
bodyfont=\color{red}\normalfont\itshape,
]{colored}
\declaretheorem[
style=colored,
name=Theorem,
]{thm}
\begin{document}
\begin{thm}
The theorem.
\end{thm}
\end{document}
答案2
您可以通过声明来实现结果,newtheoremstyle
如文档第 9 页所述amsthm
:
% declare a new theorem style
\newtheoremstyle{mystyle}%
{3pt}% Space above
{3pt}% Space below
{\itshape\color{red}}% Body font
{}% Indent amount
{\bfseries\color{blue}}% Theorem head font
{.}% Punctuation after theorem head
{.5em}% Space after theorem head
{}% Theorem head spec (can be left empty, meaning ‘normal’)
然后您可以将其用作:
% use the new theorem style
\theoremstyle{mystyle}
\newtheorem{thm}{Theorem}
这是一个完整的例子,输出与 egreg 的回答一样。
% arara: pdflatex
\documentclass{book}
\usepackage{amsthm,xcolor}
% declare a new theorem style
\newtheoremstyle{mystyle}%
{3pt}% Space above
{3pt}% Space below
{\itshape\color{red}}% Body font
{}% Indent amount
{\bfseries\color{blue}}% Theorem head font
{.}% Punctuation after theorem head
{.5em}% Space after theorem head
{}% Theorem head spec (can be left empty, meaning ‘normal’)
% use the new theorem style
\theoremstyle{mystyle}
\newtheorem{thm}{Theorem}
\begin{document}
\begin{thm}
The theorem.
\end{thm}
\end{document}