7

I'd like to customize the amsthm command a little bit but I cannot find the relevant lines in the (undocumented?) .sty.

  1. How can I put a colorbox on the name of the environment

    \newtheoremstyle{Coloredtheo}%
    {3pt}    %Space above
    {3pt}    %Space below
    {}       %Body font
    {}       %Indent amount
    {\bf \colorbox{blue}}    %Theorem head font
    {}       %Punctuation after theorem head
    {0.25em} %Space after theorem head
    {}       %Theorem head spec
    

    where the blue box should be of the size of the theorem head.

  2. how I can remove the brackets of the optional parameter

    \begin{theorem}[Schwarz inequality]... should not be (Schwarz inequality) but Schwarz inequality.

N.N.
  • 36,163
pluton
  • 16,421
  • 1
    The documentation for amsthm is in the file amsthdoc.pdf. It's probably in your distribution. Try "texdoc amsthm" from a command line. – Matthew Leingang Apr 08 '11 at 03:37
  • 1
    @Matthew -- the user documentation for amsthm is in amsthdoc.pdf. the source documentation is in amsclass.dtx. amsthm is built into the ams document classes, and the .sty file is spun off from that source. since everything is interwoven, it may be a bit obscure to pull out just the amsthm parts, but it's all there. – barbara beeton Apr 08 '11 at 12:25

3 Answers3

7
\makeatletter
\newtheoremstyle{Coloredtheo}%
{3pt}    %Space above
{3pt}    %Space below
{}   %Body font
{}   %Indent amount
{\bfseries}    %Theorem head font
{}   %Punctuation after theorem head
{0.25em} %Space after theorem head
{\colorbox{\thmbgcolor}{\color{\thmheadcolor}\thmname{#1}%
  \thmnumber{\@ifnotempty{#1}{ }\@upn{#2}}}%
  \thmnote{ {--- \the\thm@notefont#3.}}%
}   %Theorem head spec
\makeatother
\theoremstyle{Coloredtheo}
\newtheorem{genericcolorthm}{\generichead}
\newenvironment{colorthm}
  {\def\generichead{Theorem}%
   \def\thmbgcolor{blue}%
   \def\thmheadcolor{red}%
   \begin{genericcolorthm}}
  {\end{genericcolorthm}}
\newenvironment{colorlemma}
  {\def\generichead{Lemma}%
   \def\thmbgcolor{green}%
   \def\thmheadcolor{black}%
   \begin{genericcolorthm}}
  {\end{genericcolorthm}}

With two commands in the theorem style definition, you are free to give them a meaning which will be local in the environment.

egreg
  • 1,121,712
3

1 - How can I put a colorbox under the name of the environment ... where the blue box should be of the size of the theorem head.

Take a look at the thmtools package. It gives a nice key-val interface to declaring all kinds of beautiful theorem-like environments.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
2

2 - how I can remove the brackets of the optional parameter

\begin{theorem}[Schwarz inequality]... 

should not be (Schwarz inequality) but Schwarz inequality.

Put this in the preamble:

\newtheorem*{schwarz}{Schwarz Inequality}

Then in the document:

\begin{schwarz}
% ``I see your Schwarz is as big as mine.'' --- Dark Helmet, Spaceballs
\end{schwarz}

EDIT I think I understand what you want now. If you don't want a one-off environment, you can alter the theorem's head specification to typeset only the theorem note (optional argument) without delimiters, like so:

\documentclass{minimal}
\usepackage{amsthm}

\makeatletter
\newtheoremstyle{namedtheorem}%
{3pt}    %Space above
{3pt}    %Space below
{}   %Body font
{}   %Indent amount
{\bfseries}    %Theorem head font
{.}   %Punctuation after theorem head
{0.25em} %Space after theorem head
{\thmname{\@ifempty{#3}{#1}\@ifnotempty{#3}{#3}}}
\makeatother

\theoremstyle{namedtheorem}

% first argument here is the environment to be defined
% second argument is the default name of the theorem.
\newtheorem*{namedtheorem}{Theorem}

\begin{document}

\begin{namedtheorem}
One is the loneliest number.
\end{namedtheorem}

\begin{namedtheorem}[Schwarz Inequality]
For $x$ and $y$ in a Hilbert space $H$, 
\[
    |(x,y) | \leq \Vert x \Vert \cdot \Vert y \Vert
\]
\end{namedtheorem}

\end{document}

enter image description here

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195