2012年9月5日 星期三

newtheorem

要自訂新的 theorem 環境
可以用 amsthm 這個 package
非常方便
例如
\newtheorem{mynote}{Note}[chapter]
{mynote} 是新環境的名字,於是往後可以用 \begin{mynote}...\end{mynote}
{Note} 是這個新環境的標題
[chapter] 是跟編號有關
這個例子用在書的話,例如
\begin{mynote}
This is important.
\end{mynote}
大概會產生(假如是在第二章裡第一次使用)
Note 2.1.  This is important.

此外,這裡的 {mynote} 會出現在 swp 的下拉選單裡
而 {Note} 則是在 swp 的環境標題

細節的部分
說明檔已經很清楚
但是 \newtheoremstyle 的最後一個參數沒有說得很清楚
而且其實很簡單

按照說明檔:

\newtheoremstyle{note}% <name>
{3pt}% <Space above>
{3pt}% <Space below>
{}% <Body font>
{}% <Indent amount>
{\itshape}% <Theorem head font>
{:}% <Punctuation after theorem head>
{.5em}% <Space after theorem head>
{}% <Theorem head spec (can be left empty, meaning `normal')>
每個參數都算清楚
就只有最後一個參數沒說清楚
而這裡: http://users.stat.umn.edu/~geyer/amslatex.html
對最後這個 theorem head spec 有清楚的說明
(假如這個連結還在的話)

設定好這個新的 theoremstyle 之後
如果
\theoremstyle{note}
\newtheorem{mynote}{Note}[chapter]
則會把這個名叫 note 的新的 theoremstyle 套用到 mynote 這個新的 theorem 環境上
而按照上面這個 style
排出來的結果也差不多是 Note 2.1:  This is important.
就只是"Note"是斜體,還有2.1後面變冒號而已

舉個實際的例子:

\newtheoremstyle{ref}
{3pt}
{3pt}
{}
{}
{}
{}
{.5em}
{\Pointinghand\enspace [\thmnumber{#2}]}
\theoremstyle{ref}
\newtheorem{reading}{Further Reading}[chapter]

這個例子是用來當 further reading 的環境
安排在每一章之後
使得可以得到類似
-> [2.1] M. Johnson, Some Journal 99, 1234 (1995).
-> [2.2] S. Body, Some Journal 88, 4321 (1992).
的結果

新環境格式的最後一個參數我們用了{\Pointinghand\enspace [\thmnumber{#2}]}
\Pointinghand 其實是一隻手,這裡用 -> 代表,這個要\usepackage{marvosym}才行
\enspace 是插入一個小空格
\thmnumber{#2} 是編號 而我們外面用 [ ] 包起來
排出來也就照列

如果我們把這個最後一個參數留白{}
其效果等於是
{\thmname{#1}\thmnumber{ #2}}
注意到\thmnumber{ #2}裡面#2前面有個空格
而\thmname{#1}在這個例子就是Further Reading

這個實例裡
雖然我用了\newtheorem{reading}{Further Reading}[chapter]
而在設定 newtheoremstyle 時其實沒有用到\thmname{#1}
所以跟\newtheorem{reading}{}[chapter]效果其實一樣
然而差別是,前面已經提過
這個環境標題會在 swp 顯示
所以雖然不影響排版
但是在 swp 編輯的時候
看起來會比較舒服