与 xr 包交叉引用和增量编号

与 xr 包交叉引用和增量编号

我有article1.texsummary.tex。文件必须单独编译,因为我需要提交两个单独的pdf。

我正在关注本指南交叉引用article1中的方程式、图表和章节summary。然而,在 中summary我进一步定义了方程式和图表,它们的编号又从 1 开始。

我需要的是 a) 编号不再从 1 开始(首选解决方案),b) 引用方程式和图形时,它们要有一个前缀,例如,如果图形在摘要中,则要使用“图 S1”而不是“图 1”(类似于可以做什么\appendix以及重命名部分)。

MWE 是Overleaf 示例.只需添加

This is a new Equation
\begin{equation}
x + y    
\end{equation}
That should start from number 2 but starts from 1.

summary.tex

或者,这里也有完整的示例。

summary.tex

\documentclass[12pt]{article}

\title{Using the xr package on Overleaf}

%----Helper code for dealing with external references----
% (by cyberSingularity at http://tex.stackexchange.com/a/69832/226)

\usepackage{xr}
\makeatletter

\newcommand*{\addFileDependency}[1]{% argument=file name and extension
\typeout{(#1)}% latexmk will find this if $recorder=0
% however, in that case, it will ignore #1 if it is a .aux or 
% .pdf file etc and it exists! If it doesn't exist, it will appear 
% in the list of dependents regardless)
%
% Write the following if you want it to appear in \listfiles 
% --- although not really necessary and latexmk doesn't use this
%
\@addtofilelist{#1}
%
% latexmk will find this message if #1 doesn't exist (yet)
\IfFileExists{#1}{}{\typeout{No file #1.}}
}\makeatother

\newcommand*{\myexternaldocument}[1]{%
\externaldocument{#1}%
\addFileDependency{#1.tex}%
\addFileDependency{#1.aux}%
}
%------------End of helper code--------------

% put all the external documents here!
\myexternaldocument{article1}

\begin{document}

In the file \texttt{article1.tex}, the introduction is section \ref{introduction}.  In that file, there are two subsections: \ref{mathrefs} and \ref{powers}. In subsection \ref{powers}, equation \ref{eq:1} demonstrates a power series.

This is a new Equation
\begin{equation}
x + y    
\end{equation}
That should start from number 2 but starts from 1.

\end{document}

article1.tex

\documentclass{article}
\title{This is \texttt{article1.tex}}
\begin{document}
\section{Introduction}
\label{introduction}

This is a standalone \LaTeX{} document with
references we want to use in \texttt{summary.tex}.

\subsection{Math references}
\label{mathrefs}
As mentioned in section \ref{introduction}, 
different elements can be referenced within
a document.

\subsection{Powers series}
\label{powers}

\begin{equation}
\label{eq:1}
\sum_{i=0}^{\infty} a_i x^i
\end{equation}

Equation \ref{eq:1} is a typical power series.
\end{document}

答案1

根据 Ulrike 的评论,我发现了几种可以满足我需求的方法。无论你选择哪种,它都会在之后出现\maketitle

解决方案 1

这不会重置编号。您需要手动插入最后一个方程式/表格/...的标签main.tex

\setcounter{equation}{\getrefnumber{eq:last_main_eq}}
\setcounter{figure}{\getrefnumber{fig:last_main_fig}} 
% and so on

解决方案 2

非常通用,这将使用部分名称重命名您的图形/方程式/...。如果部分名称已被更改\appendix,它们将类似于“图 A.1”。

\counterwithin{figure}{section}
\counterwithin{table}{section}
\counterwithin{equation}{section}
% and whatever else you need

解决方案 3

和之前类似,但是可以进行更多定制。

\renewcommand{\theequation}{\thesection.\arabic{equation}} % Figure A.1, A.2, B.1, ...
\renewcommand{\thefigure}{\thesection.\arabic{figure}} 
% and again, whatever else you'd need 

相关内容