![如何引用图表或表格的部分(故意的!)](https://linux22.com/image/314882/%E5%A6%82%E4%BD%95%E5%BC%95%E7%94%A8%E5%9B%BE%E8%A1%A8%E6%88%96%E8%A1%A8%E6%A0%BC%E7%9A%84%E9%83%A8%E5%88%86%EF%BC%88%E6%95%85%E6%84%8F%E7%9A%84%EF%BC%81%EF%BC%89.png)
有没有办法引用定义特定图形或表格的部分?我知道引用图形的部分通常是一个错误(即意外地将 放在\label{}
标题之前),但我想故意这样做,当然,将 放在\label{}
标题之后。
我想我正在寻找某种\sectionof{myfig}
不存在的命令。
答案1
这应用了 Heiko Oberdiek 设计的非常复杂的包zref
,极大地扩展了标签/参考系统。
标签有property
列表,因此,图形标签应该有一个figsection
属性,其中包含生成图形标签的部分编号。
\makeatletter
\zref@newlist{section} % define a larger list of section properties
\zref@newprop{figsection}[undefined]{\number\value{section}} % define the property `figsection` and store the section number.
\zref@addprop{section}{figsection} % couple figsection to section list
\newcommand{\figsectionlabel}[1]{% Wrapper for `\zref@label..
\label{#1}% Set a traditional label
\zref@labelbylist{#1}{section} % Add the label #1 to the property list section % Basically a hook is executed
}%
\newcommand{\sectionof}[1]{%
\zref@extract{#1}{figsection}% Wrapper
}
\makeatother
\documentclass{book}
\usepackage[user]{zref}
\usepackage{hyperref}
\usepackage{cleveref}
\makeatletter
\zref@newlist{section}
\zref@newprop{figsection}[undefined]{\number\value{section}}
\zref@addprop{section}{figsection}
\newcommand{\figsectionlabel}[1]{%
\label{#1}% Set a traditional label
\zref@labelbylist{#1}{section} % Add the label #1 to the property list section
}%
\newcommand{\sectionof}[1]{%
\zref@extract{#1}{figsection}%
}
\makeatother
\begin{document}
\chapter{My sophisticated \LaTeX\ code}
Figure \ref{secondfig} is placed in Section \sectionof{secondfig} and \ref{fourthfig} can be found in \sectionof{fourthfig}
\section{First} \label{firstsec}
\begin{figure}
\caption{Some dummy figure} \label{firstfig}
\end{figure}
\section{Two}
\begin{figure}
\caption{Some dummy figure Nr. 2} \figsectionlabel{secondfig}
\end{figure}
\begin{figure}
\caption{Some dummy figure Nr. 3} \label{thirdfig}
\end{figure}
\section{Three}
\section{Four}
\section{Five}
\begin{figure}
\caption{Some dummy figure Nr. 4} \figsectionlabel{fourthfig}
\end{figure}
\end{document}