交叉引用:公式、图表、章节、节等

交叉引用:公式、图表、章节、节等

当我们引用方程式时,我们可以使用\eqref,而当我们引用图形时,我们可以使用\fref。然后方程式的引用具有( ),并且单词figure被插入到文档位置。是否有章节、节、小节、小节等的引用?

这样,当我引用该部分时,我就可以这样做\somethingrefsection~\ref

答案1

我建议你cleveref作为另一种选择。虽然hyperref\autoref功能强大,但\cref( \Cref) 的cleveref功能更强大,而且更容易定制。一些比较:

\documentclass{book}
\usepackage[colorlinks=true]{hyperref}
\usepackage{cleveref}

\begin{document}

\chapter{First Chapter}\label{chapter}
\section{Some Section}\label{sectiona}
\section{Some Other Section}\label{sectionb}

\begin{figure}[!ht]
  \centering
  \rule{30mm}{20mm}
  \caption{Some Figure}\label{figure}
\end{figure}

Using \texttt{\textbackslash autoref}, we can refer to \autoref{chapter}, \autoref{sectiona}, and \autoref{figure}, but using a range fails:~\autoref{sectiona,sectionb}

Using \texttt{\textbackslash cleveref}, we can refer to \cref{chapter}, \cref{sectiona}, and \cref{figure}. \Cref{chapter}. \Cref{sectiona}. \Cref{figure}. A range has no problem now:~\cref{sectiona,sectionb}

\end{document}

在此处输入图片描述

您想让对象名称成为超链接的一部分吗?您可以使用nameinlink以下选项cleveref

\documentclass{book}
\usepackage[colorlinks=true]{hyperref}
\usepackage[nameinlink]{cleveref}

\begin{document}

\chapter{First Chapter}\label{chapter}
\section{Some Section}\label{sectiona}
\section{Some Other Section}\label{sectionb}

\begin{figure}[!ht]
  \centering
  \rule{30mm}{20mm}
  \caption{Some Figure}\label{figure}
\end{figure}

Using \texttt{\textbackslash autoref}, we can refer to \autoref{chapter}, \autoref{sectiona}, and \autoref{figure}, but using a range fails:~\autoref{sectiona,sectionb}

Using \texttt{\textbackslash cleveref}, we can refer to \cref{chapter}, \cref{sectiona}, and \cref{figure}. \Cref{chapter}. \Cref{sectiona}. \Cref{figure}. A range has no problem now:~\cref{sectiona,sectionb}

\end{document}

在此处输入图片描述

想要更改超链接的默认格式?使用\crefdefaultlabelformat

\documentclass{book}
\usepackage[colorlinks=true]{hyperref}
\usepackage{cleveref}

\crefdefaultlabelformat{[#2#1#3]}

\begin{document}

\chapter{First Chapter}\label{chapter}
\section{Some Section}\label{sectiona}
\section{Some Other Section}\label{sectionb}

\begin{figure}[!ht]
  \centering
  \rule{30mm}{20mm}
  \caption{Some Figure}\label{figure}
\end{figure}

Using \texttt{\textbackslash autoref}, we can refer to \autoref{chapter}, \autoref{sectiona}, and \autoref{figure}, but using a range fails:~\autoref{sectiona,sectionb}

Using \texttt{\textbackslash cleveref}, we can refer to \cref{chapter}, \cref{sectiona}, and \cref{figure}. \Cref{chapter}. \Cref{sectiona}. \Cref{figure}. A range has no problem now:~\cref{sectiona,sectionb}

\end{document}

在此处输入图片描述

答案2

\autoref从包装来看怎么样hyperref

在此处输入图片描述

\documentclass{book}

\usepackage{hyperref}

\begin{document}

\chapter{First Chapter}\label{chapter}

\section{Some Section}\label{section}

\begin{figure}[h!]
  \centering
  \rule{30mm}{20mm}
  \caption{Some Figure}\label{figure}
\end{figure}

Using \texttt{\textbackslash autoref}, we can refer to \autoref{chapter}, \autoref{section},
and \autoref{figure}.

\end{document}

对于用户定义的环境,如引理、命题等,只需定义

\<env_name>autorefname

其中,<env_name>是要引用的环境的名称。有关详细信息,请参阅这个帖子

答案3

(附近)任何你想要的东西。例如:\def\somethingref#1{section~\ref{#1}}。但如果你喜欢部分,它可以是\def\somethingref#1{My $\heartsuit$~section~\ref{#1}}。:-)

相关内容