我制作了一个“假设”自定义计数器,以便让 LaTeX 处理我的假设引用。我的代码是
\newcounter{hypothese}
\refstepcounter{hypothese}\label{hypo:lenght_of_words}
\refstepcounter{hypothese}\label{hypo:blue_word}
I think thant the words will be longer in this condition (hypothesis
\ref{hypo:lenght_of_words}) and that the word \emph{blue} will be user more
frenquently than in the next situation (hypothesis \ref{hypo:blue_word}).
% ... statistical computing
As predicted in hypothesis \ref{hypo:blue_word}, the word \enquote{blue} is much more
used than in the natural condition.
输出是我想要的:
I think thant the words will be longer in this condition (hypothesis 1) and that the
word blue will be user more frenquently than in the next situation (hypothesis 2).
As predicted in hypothesis 2, the word « blue » is much more used than in the natural
condition.
现在我希望假设使用\Alph{}
编号样式(,,,A
... ),但我不知道如何设置命令以返回字母。有人能帮帮我吗?B
C
\ref{}
答案1
默认情况下,\newcounter{hypothese}
将新创建的计数器的编号样式设置hypothese
为阿拉伯数字(1、2、3、...)。但是,可以轻松更改编号样式。例如,要将样式设置为大写字母(A、B、C、...),您应该插入
\renewcommand{\thehypothese}{\Alph{hypothese}}
最好是在定义相关计数器之后立即执行(请参阅下面的代码)。可能需要两次编译才能获得所需的结果。
边注:您可以通过避免硬编码“假设”来省去一些麻烦。使用当前方法,如果您稍后决定将文档中所有交叉引用的“假设”实例更改为“假设”,那么您将面临一些繁琐且容易出错的搜索和替换。更易于维护的替代方案是使用prettyref
包及其\newrefformat
命令\prettyref
;例如,如果您决定在稍后的阶段将“假设”替换为“假设”,则只需在命令的第二个参数中Assumption
替换即可。更改将反映在整个文档中。一个更强大(尽管使用起来不那么简单)的包是Hypothesis
\newrefformat
cleveref
。
\documentclass{article}
\usepackage{csquotes}
\setlength\parindent{0pt}
\usepackage{prettyref}
\newrefformat{hypo}{Hypothesis~\ref{#1}}
\begin{document}
\newcounter{hypothese}
\renewcommand{\thehypothese}{\Alph{hypothese}}
\refstepcounter{hypothese}\label{hypo:lenght_of_words}
Hypothesis~\thehypothese\\[1em]
\refstepcounter{hypothese}\label{hypo:blue_word}
Hypothesis~\thehypothese\\
I think thant the words will be longer in this condition
(\prettyref{hypo:lenght_of_words}) and that the word \emph{blue}
will be user more frequently than in the next situation (\prettyref{hypo:blue_word}).\\
% ... statistical computing
As predicted in \prettyref{hypo:blue_word}, the word \enquote{blue} is much more
used than in the natural condition.
\end{document}