如何正确重复浮动(图形或表格)?

如何正确重复浮动(图形或表格)?

我在不同的章节中引用了浮动。为了让读者更容易理解,我想重复整个浮动,这样读者就不需要跳回到浮动第一次出现的章节。如何正确地做到这一点?理想情况下,它应该涉及浮动的标签来确定应该重复哪个浮动,并且应该可以给它一个新的标签命令。

这不是重复的两次使用相同的数字,没有新的数字因为我既不想重复相同的图号,答案也没有解决重复内容(图像或表格)的问题。

\documentclass{book}
\usepackage{float}
\usepackage{graphicx}
\usepackage{nameref}
\usepackage{refstyle}

\begin{document}

\chapter{One}

Consider \figref{MyImage}.

\begin{figure}
\includegraphics{example-image-a}
\caption{My Image\label{fig:MyImage}}
\end{figure}

\chapter{Two}

Consider again \figref{MyImageAgain}.

% Some command to repeat a figure with two arguments
% 1. its label, "fig:MyImage", so it is known what should be repeated
% 2. its new custom label command, "\label{fig:MyFigureAgain}"
% - repeats its content
% - sets its caption to \caption{\nameref{fig:MyImage} (repeated from page \pageref{fig:MyImage})}.
% - set its label by using "\label{fig:MyFigureAgain}"
% So it should produce something like
%
% \begin{figure}
% \includegraphics{example-image-a}
% \caption{\nameref{fig:MyImage} (repeated from page \pageref{fig:MyImage})\label{fig:MyImageAgain}}
% \end{figure}

\end{document}

答案1

一个 hack,但是如何为图的主体(包括标题但不包含标签)定义宏并使用它们呢?您确实说过您只关心几个图。大致如下(未经测试):

\newcommand{\figa}[1]{main contents of figure \caption{#1}}
\newcommand{\figb}[1]{contents of another figure \caption{#1}}
...
\begin{figure}
  \centering
  \figa{First caption}
  \label{figafirst}
\end{figure}
In figure \ref{figafirst} ...
...
\begin{figure}
  \centering
  \figa{Modified caption}
  \label{figanext}
\end{figure}
Figure \ref{figafirst} is repeated as \ref{figanext}.

% and so on

相关内容