出于某种搞笑,我想提出一个带有分数的定理。如果我必须具体给出数字,那就完全没问题。
然而,我确实不是想要为此定义一个新的环境,因为我想重用该定理的样式,并且希望在我改变该定理的布局时它也随之改变。
我尝试了类似的方法\renewcommand{\thetheorem}{9$\fraction{3}{4}}
,但这不起作用,因为\refstepcounter
(由定理自动调用)只是覆盖了它,而我不知道如何防止这种情况发生。
我知道这有点傻而且没有什么实际用途,但这仍然是我想做的一件有趣的事。
编辑:
我用它thmtools
来生成我的定理环境,但这似乎不是一个问题,它仍然有效。
但是,我的问题似乎是包cleveref
和我希望它适用于与定理共享计数器的定义这一事实的结合。如果我cleveref
只使用定理,一切都很好。如果我不使用cleveref
,下面的代码也适用于定义,与定理共享计数器。
但是,当我同时使用它们时,我就会得到编译错误,并且定义会变得混乱。警告似乎也帮不上什么忙。
下面是一个 MWE(注释掉时有效cleveref
,但在使用包时失败):
\documentclass{article}
\usepackage{amsmath,amsthm}
%\usepackage{cleveref}
\usepackage{hyperref}
\newtheorem{theorem}{Theorem}
\newtheorem{definition}[theorem]{Definition}
\begin{document}
See Theorem~\ref{thm:first}, Theorem~\ref{thm:second} or Theorem~\ref{thm:third} or Definition~\ref{def:third}.
\begin{theorem}
First theorem.\label{thm:first}
\end{theorem}
\begin{theorem}[Second]
Second theorem.\label{thm:second}
\end{theorem}
\begingroup
\renewcommand{\refstepcounter}[1]{}% Remove functionality of \refstepcounter
%\stepcounter{theorem}% Step default theorem counter % Commented out because using hyperref
\renewcommand{\thetheorem}{\arabic{theorem}$\mathbf{\tfrac{3}{4}}$}% Setup printing of theorem counter
\begin{theorem}
Third theorem.%
\makeatletter
\renewcommand{\@currentlabel}{\arabic{theorem}$\tfrac{3}{4}$}% Update theorem reference
\makeatother
\label{thm:third}% Capture reference in \label
\end{theorem}
\endgroup
\begingroup
\renewcommand{\refstepcounter}[1]{}% Remove functionality of \refstepcounter
%\stepcounter{theorem}% Step default theorem counter % Commented out because using hyperref
\renewcommand{\thetheorem}{\arabic{theorem}$\mathbf{\tfrac{3}{4}}$}% Setup printing of theorem counter
\begin{definition}
Third theorem.%
\makeatletter
\renewcommand{\@currentlabel}{\arabic{theorem}$\tfrac{3}{4}$}% Update theorem reference
\makeatother
\label{def:third}% Capture reference in \label
\end{definition}
\endgroup
\begin{theorem}
Fifth theorem.
\end{theorem}
\end{document}
答案1
您需要做一些手动的工作,但这是可行的:
\documentclass{article}
\usepackage{amsmath,amsthm}
\newtheorem{theorem}{Theorem}
\begin{document}
See Theorem~\ref{thm:first}, Theorem~\ref{thm:second} or Theorem~\ref{thm:third}.
\begin{theorem}
First theorem.\label{thm:first}
\end{theorem}
\begin{theorem}[Second]
Second theorem.\label{thm:second}
\end{theorem}
\begingroup
\renewcommand{\refstepcounter}[1]{}% Remove functionality of \refstepcounter
\stepcounter{theorem}% Step default theorem counter
\renewcommand{\thetheorem}{\arabic{theorem}$\mathbf{\tfrac{3}{4}}$}% Setup printing of theorem counter
\begin{theorem}
Third theorem.%
\makeatletter
\renewcommand{\@currentlabel}{\arabic{theorem}$\tfrac{3}{4}$}% Update theorem reference
\makeatother
\label{thm:third}% Capture reference in \label
\end{theorem}
\endgroup
\begin{theorem}
Fourth theorem.
\end{theorem}
\end{document}
\stepcounter{theorem}
如果你正在使用,删除它似乎就足够了hyperref
也一样。
答案2
答案3
假设“gag”以最后一个定理数作为主数,那就更容易了……
只需注意hyperref
并指定一个唯一的锚点名称即可。我们还需要说服amsthm
在定理头中使用粗体数学。请注意cleveref
应该在之后hyperref
。
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{hyperref}
\usepackage{cleveref}
\newtheorem{theorem}{Theorem}
\newtheorem{definition}[theorem]{Definition}
\newcounter{gag}
\makeatletter
\newenvironment{gag}[1]{%
\let\savedthetheorem\thetheorem
\thm@headfont{\bfseries\boldmath}%
\stepcounter{gag}%
\renewcommand{\thetheorem}{\savedthetheorem#1}%
\renewcommand{\theHtheorem}{gag\thegag}%
\addtocounter{theorem}{-1}\ignorespaces
}{\ignorespacesafterend}
\makeatother
\begin{document}
See \Cref{thm:first}, \Cref{thm:second} or
\Cref{thm:third} or \Cref{def:third}.
\begin{theorem}
First theorem.\label{thm:first}
\end{theorem}
\begin{theorem}[Second]
Second theorem.\label{thm:second}
\end{theorem}
\begin{gag}{$\frac{3}{4}$}
\begin{theorem}\label{thm:third}
Third theorem.
\end{theorem}
\end{gag}
\begin{gag}{$\frac{3}{4}$}
\begin{definition}\label{def:third}
Definition.
\end{definition}
\end{gag}
\begin{theorem}
Fifth theorem.
\end{theorem}
\end{document}