我在方程中使用了\label
和\ref
。例如
\begin{equation}
\label{eq:grav} F=\frac{G m_{1} m_{2}}{r^{2}}
\end{equation}
如方程式所示\ref{eq:grav}
打印方程式排列顺序的数字(参考文档中的其他方程式)。
我希望它不仅打印数字,还打印单词“方程”,因为我总是需要说它是一个方程,所以不必总是手动输入就好了。数字也是一样。
有没有办法在序言中定义这一点?
答案1
\documentclass{report}
\usepackage{hyperref} %% to turn the links clickable and load this before cleveref
\usepackage{cleveref}
% each of the following has two versions
% \crefname{environmentname}{singular}{plural}, to be used mid-sentence
% \Crefname{environmentname}{singular}{plural}, to be used at the beginning of a sentence
\crefname{table}{table}{tables}
\Crefname{table}{Table}{Tables}
\crefname{figure}{figure}{figures}
\Crefname{figure}{Figure}{Figures}
\crefname{equation}{equation}{equations}
\Crefname{Equation}{Equation}{Equation}
\begin{document}
\begin{figure}[!htb]
\centering
\rule{20pt}{20pt}
\caption{My figure}
\label{fig:myfig}
\end{figure}
\begin{equation}
\label{eq:grav} F=\frac{G m_{1} m_{2}}{r^{2}}
\end{equation}
\begin{itemize}
\item Use \cref{fig:myfig} mid sentence.
\item \Cref{fig:myfig} is appropriate for the beginning of a sentence and~\cref{eq:grav}. \Cref{eq:grav} is printing \verb|Equation| rather than \verb|equation|.
\end{itemize}
\end{document}
答案2
我提供的与 Harish Kumar 提供的类似,但我提供了一些附加选项。下面我提供的是一个样式文件,eqcite.sty
\ProvidesPackage {eqcite} [2006/11/29]
%
% by Steven B. Segletes, for the public domain.
%
% eqcite prints out the preferred reference format for equation
% citations, e.g., equation 1 as opposed to eqn(1), eq.(1), etc.
%
% Advantages of using eqcite:
% 1) Ability to quickly change from `equation x' to `eqn(x)' through
% whole document, with a single line change (\EqTypeB). This is
% useful when converting from tech report to manuscript formats;
% 2) Saves typing:
% With the eqcite package, type `\eqcite{eq:myeqn}'
% vs. the traditional LaTeX approach of `equation~\ref{eq:myeqn}' .
%
%
% A number of format types are predefined:
%
% EqTypeA : equation x, equations x and y (ARL report standard)
% EqTypeB : eqn(x) , eqns (x) and (y)
% EqTypeC : eq(x) , eqs (x) and (y)
% EqTypeD : eqn.(x) , eqns. (x) and (y)
% EqTypeE : eq.(x) , eqs. (x) and (y)
% EqTypeF : eqn (x) , eqns (x) and (y)
% EqTypeG : eq (x) , eqs (x) and (y)
%
% Other format types are easily added.
%
% Usage:
%
% % In Preamble:
% \usepackage{eqcite}
% \EqTypex % where `x' is A, B, etc. defaults to EqTypeA
%
% % In Document:
% \Eqcite{ref} ...
% ... \eqcite{ref} ...
% \Eqcites{ref1}, \andeqcite{ref2}, and \andeqcite{ref3} ...
% ... \eqcites{ref1}, \andeqcite{ref2}, and \andeqcite{ref3}...
%
% where ref is the LaTeX reference, for example, eq:myeqn .
%
% A literal option [l] is available to use the the argument as the
% actual equation number, rather than as an equation reference:
%
% \eqcite[l]{13}
%
% This literal option can be used with the following calls:
% \Eqcite, \eqcite, \Eqcites, \eqcites and \andeqcite.
%
%
% EqTypeA : equation x, equations x and y
\newcommand\EqTypeA{
\def\Eqname{Equation}
\def\eqname{equation}
\def\Eqsname{Equations}
\def\eqsname{equations}
\def\eqsep{~}
\def\eqssep{~}
\def\eqldelimit{}
\def\eqrdelimit{}
}
% EqTypeB : eqn(x), eqns (x) and (y)
\newcommand\EqTypeB{
\def\Eqname{Eqn}
\def\eqname{eqn}
\def\Eqsname{Eqns}
\def\eqsname{eqns}
\def\eqsep{}
\def\eqssep{~}
\def\eqldelimit{(}
\def\eqrdelimit{)}
}
% EqTypeC : eq(x), eqs (x) and (y)
\newcommand\EqTypeC{
\def\Eqname{Eq}
\def\eqname{eq}
\def\Eqsname{Eqs}
\def\eqsname{eqs}
\def\eqsep{}
\def\eqssep{~}
\def\eqldelimit{(}
\def\eqrdelimit{)}
}
% EqTypeD : eqn.(x), eqns. (x) and (y)
\newcommand\EqTypeD{
\def\eqname{Eqn.}
\def\eqname{eqn.}
\def\Eqsname{Eqns.}
\def\eqsname{eqns.}
\def\eqsep{}
\def\eqssep{~}
\def\eqldelimit{(}
\def\eqrdelimit{)}
}
% EqTypeE : eq.(x), eqs. (x) and (y)
\newcommand\EqTypeE{
\def\Eqname{Eq.}
\def\eqname{eq.}
\def\Eqsname{Eqs.}
\def\eqsname{eqs.}
\def\eqsep{}
\def\eqssep{~}
\def\eqldelimit{(}
\def\eqrdelimit{)}
}
% EqTypeF : eqn (x), eqns (x) and (y)
\newcommand\EqTypeF{
\def\Eqname{Eqn}
\def\eqname{eqn}
\def\Eqsname{Eqns}
\def\eqsname{eqns}
\def\eqsep{~}
\def\eqssep{~}
\def\eqldelimit{(}
\def\eqrdelimit{)}
}
% EqTypeG : eq (x), eqs (x) and (y)
\newcommand\EqTypeG{
\def\Eqname{Eq}
\def\eqname{eq}
\def\Eqsname{Eqs}
\def\eqsname{eqs}
\def\eqsep{~}
\def\eqssep{~}
\def\eqldelimit{(}
\def\eqrdelimit{)}
}
% Default to Equation Type A format
\EqTypeA
%
% For citing an equation at the beginning of a sentence
\newcommand\Eqcite[2][]{%
\if l#1%
\Eqname\eqsep\eqldelimit#2\eqrdelimit
\else%
\Eqname\eqsep\eqldelimit\ref{#2}\eqrdelimit
\fi
}
% For citing an equation in the middle of a sentence
\newcommand\eqcite[2][]{%
\if l#1%
\eqname\eqsep\eqldelimit#2\eqrdelimit
\else%
\eqname\eqsep\eqldelimit\ref{#2}\eqrdelimit
\fi
}
% For citing the first of multiple equations at the beginning of a sentence
\newcommand\Eqcites[2][]{%
\if l#1%
\Eqsname\eqssep\eqldelimit#2\eqrdelimit
\else%
\Eqsname\eqssep\eqldelimit\ref{#2}\eqrdelimit
\fi
}
% For citing the first of multiple equations in the middle of a sentence
\newcommand\eqcites[2][]{%
\if l#1%
\eqsname\eqssep\eqldelimit#2\eqrdelimit
\else%
\eqsname\eqssep\eqldelimit\ref{#2}\eqrdelimit
\fi
}
% For citing an equation number without the leading word equation, eqn, etc.
% Used in conjuction with \Eqcites and \eqcites
\newcommand\andeqcite[2][]{%
\if l#1%
\eqldelimit#2\eqrdelimit
\else%
\eqldelimit\ref{#2}\eqrdelimit
\fi
}
%
% For backward compatibility to equagen.sty
\let\equagen\eqcite
\let\Equagen\Eqcite
\let\equagens\eqcites
\let\Equagens\Eqcites
\let\andequagen\andeqcite
\endinput
首先,您可以指定 EqType,其中类型可以是“equation”、“eqn”等。然后,它为引用提供复数、单数、大写、连词和文字选项。