我使用amsthm
和amsbook
。我想知道如何将定理数字放在矩形框中,无论是第一次出现时还是引用时。这是一张现在的样子
:应该看起来像:
这是我的意思的 MWE:
%% LyX 2.2.0dev created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[oneside,english,reqno]{amsbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{luainputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm}
\setcounter{secnumdepth}{5}
\usepackage{amsthm}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\swapnumbers
\theoremstyle{plain}
\newtheorem{thm}{\protect\theoremname}[section]
\theoremstyle{plain}
\newtheorem{claim}[thm]{\protect\claimname}
\theoremstyle{definition}
\newtheorem{defn}[thm]{\protect\definitionname}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage[breaklinks,colorlinks=true,linkcolor=blue,
citecolor=blue, urlcolor=blue]{hyperref}
\usepackage{braket}
\usepackage{mathtools}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%
\let\oldnorm\norm
\def\norm{\@ifstar{\oldnorm}{\oldnorm*}}
\makeatother
\usepackage{amsfonts}
\usepackage{dsfont}
\renewcommand{\vec}[1]{\mathbf{#1}}
\usepackage[scaled=0.88]{beraserif}
\usepackage[scaled=0.85]{berasans}
\usepackage[scaled=0.84]{beramono}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage[T1,small,euler-digits]{eulervm}
\numberwithin{section}{chapter}
% remove theorem indentation
% -------------
\makeatletter
\let\sv@thm\@thm
\def\@thm{\let\indent\relax\sv@thm}
\makeatother
% -------------
\usepackage{etoolbox}
\expandafter\patchcmd\csname\string\proof\endcsname
{\normalparindent}{0pt }{}{}
\AtBeginDocument{
\def\labelitemii{\(\circ\)}
\def\labelitemiv{\(\star\)}
}
\makeatother
\usepackage{babel}
\providecommand{\claimname}{Claim}
\providecommand{\definitionname}{Definition}
\providecommand{\theoremname}{Theorem}
\begin{document}
\title{Title}
\maketitle
\chapter{First Chapter}
\section{First Section}
Here is some text. As it begins a paragraph, it starts indented. Bla
bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla
bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla.
Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla
bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla
bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla.
\begin{claim}
\label{claim:Cool_Claim}Some Claim {[}some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words{]}
\begin{proof}
this is a proof
\end{proof}
\end{claim}
\begin{defn}
Some Definition
\end{defn}
This is now normal text again. As we learnt in \ref{claim:Cool_Claim}.
\end{document}
答案1
下面我展示了两种可能性:一是使用一些定制的定理样式,二是重新定义计数器。
使用一些定制的定理样式
plainboxed
,definitionboxed
基本上将数字放在里面\fbox
;还定义了一个新命令\thref
,因此交叉引用也被装箱(\swapnumbers
不应再使用):\documentclass[oneside,english,reqno]{amsbook} \usepackage{etoolbox} \makeatletter \newtheoremstyle{plainboxed} {\thm@preskip} {\thm@postskip} {\itshape} {0pt} {\scshape} {.} {.5em} {\smash{\fbox{\thmnumber{#2.}}}~\thmname{#1}\thmnote{~{\normalfont(#3)}}} \newtheoremstyle{definitionboxed} {\thm@preskip} {\thm@postskip} {\normalfont} {0pt} {\scshape} {.} {.5em} {\smash{\fbox{\thmnumber{#2.}}}~\thmname{#1}\thmnote{~{\normalfont(#3)}}}% \theoremstyle{plainboxed} \newtheorem{thm}{\protect\theoremname}[section] \newtheorem{claim}[thm]{\protect\claimname} \theoremstyle{definitionboxed} \newtheorem{defn}[thm]{\protect\definitionname} \numberwithin{section}{chapter} \makeatletter \let\sv@thm\@thm \def\@thm{\let\indent\relax\sv@thm} \let\oldref\ref \newcommand\thref[1]{\textup{\fbox{\ref{#1}}}} \makeatother \expandafter\patchcmd\csname\string\proof\endcsname {\normalparindent}{0pt }{}{} \makeatother \providecommand{\claimname}{Claim} \providecommand{\definitionname}{Definition} \providecommand{\theoremname}{Theorem} \begin{document} \chapter{First Chapter} \section{First Section} \begin{claim} \label{claim:Cool_Claim}Some Claim some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words \begin{proof} this is a proof \end{proof} \end{claim} \begin{defn} Some Definition \end{defn} This is now normal text again. As we learnt in \thref{claim:Cool_Claim}. \end{document}
重新定义计数器;代码更短了,但现在数字的格式并不完全符合要求(最后一个点在框外面):
\documentclass[oneside,english,reqno]{amsbook} \usepackage{etoolbox} \makeatletter \swapnumbers \theoremstyle{plain} \newtheorem{thm}{\protect\theoremname}[section] \newtheorem{claim}[thm]{\protect\claimname} \theoremstyle{definition} \newtheorem{defn}[thm]{\protect\definitionname} \numberwithin{section}{chapter} \let\theoldthm\thethm \let\theoldclaim\theclaim \let\theolddefn\thedefn \renewcommand\thethm{\fbox{\theoldthm}} \renewcommand\theclaim{\fbox{\theoldclaim}} \renewcommand\thedefn{\fbox{\theolddefn}} \makeatletter \let\sv@thm\@thm \def\@thm{\let\indent\relax\sv@thm} \makeatother \expandafter\patchcmd\csname\string\proof\endcsname {\normalparindent}{0pt }{}{} \makeatother \providecommand{\claimname}{Claim} \providecommand{\definitionname}{Definition} \providecommand{\theoremname}{Theorem} \begin{document} \chapter{First Chapter} \section{First Section} \begin{claim} \label{claim:Cool_Claim}Some Claim some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words some words \begin{proof} this is a proof \end{proof} \end{claim} \begin{defn} Some Definition \end{defn} This is now normal text again. As we learnt in \ref{claim:Cool_Claim}. \end{document}
更新
使用该thmtools
包作为的前端amsthm
,第一种方法的代码简化了:
\documentclass[oneside,english,reqno]{amsbook}
\usepackage{etoolbox}
\usepackage{thmtools}
\makeatletter
\providecommand{\claimname}{Claim}
\providecommand{\definitionname}{Definition}
\providecommand{\theoremname}{Theorem}
\declaretheoremstyle[
spaceabove=\thm@preskip,
spacebelow=\thm@postskip,
headfont=\normalfont\scshape,
notefont=\mdseries,
notebraces={(}{)},
numberwithin=section,
headformat=\smash{\fbox{\NUMBER.}}~\NAME\NOTE,
bodyfont=\BodyFont,
]{boxed}
\def\BodyFont{\normalfont\itshape}
\declaretheorem[style=boxed,name=\theoremname]{thm}
\declaretheorem[style=boxed,name=\claimname]{claim}
\def\BodyFont{\normalfont}
\declaretheorem[style=boxed,name=\definitionname]{defn}
\numberwithin{section}{chapter}
\makeatletter
\let\sv@thm\@thm
\def\@thm{\let\indent\relax\sv@thm}
\let\oldref\ref
\newcommand\thref[1]{\textup{\fbox{\ref{#1}}}}
\expandafter\patchcmd\csname\string\proof\endcsname
{\normalparindent}{0pt }{}{}
\makeatother
\begin{document}
\chapter{First Chapter}
\section{First Section}
\begin{claim}
\label{claim:Cool_Claim}Some Claim some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words
\begin{proof}
this is a proof
\end{proof}
\end{claim}
\begin{defn}
Some Definition
\end{defn}
This is now normal text again. As we learnt in \thref{claim:Cool_Claim}.
\end{document}
评论
作为芭芭拉·比顿提及她的评论,如果数字被框起来,它们实际上不需要以句号结尾。在第一种方法\thmnumber{#2.}
中用替换\thmnumber{#2}
将取消最后的句号;thmtools 方法中所需的更改是将 替换 headformat=\smash{\fbox{\NUMBER.}}~\NAME\NOTE
为headformat=\smash{\fbox{\NUMBER}}~\NAME\NOTE