从外部文件中交叉引用表格的标题全名(一个表格是“longtblr”)

从外部文件中交叉引用表格的标题全名(一个表格是“longtblr”)

问题。

我有以下文件,它们共同构成了我的平均能量损失

  1. main.tex
  2. SupplementaryMaterial.tex
  3. wlscirep_modified.cls(从提交给科学报告官方的模板
  4. latexmkrc(从与 Overleaf 中的 xr 包进行交叉引用

\documentclass我对所调用的做了一些小的修改wlscirep.cls,我确实将其重命名为wlscirep_modified.cls

在此处输入图片描述

main.tex我需要交叉引用名为的外部文件中的两个表SupplementaryMaterial.tex,但是当我尝试引用这两个表时,我得到了以下结果:

在此处输入图片描述

如您所见,我没有得到标题的全名,即“补充表 1”和“补充表 2”,而只得到了数字“1”作为第一个表的交叉引用,以及双问号“??”作为第二个表(即“longtblr”)的交叉引用。

因此,我希望的输出如下:

在此处输入图片描述

请问您对如何获得我想要的输出有什么建议吗?

用过的文件。

  1. main.tex
\documentclass[twocolumn,fleqn,10pt,dvipsnames,table]{wlscirep_modified}
\usepackage{xcolor}

\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{SupplementaryMaterial}

\begin{document}

In \texttt{SupplementaryMaterial.tex} we have \ref{tab:first_table} 
and \ref{tab:second_table}.

\end{document}
  1. SupplementaryMaterial.tex
\documentclass[twocolumn,fleqn,10pt,dvipsnames,table]{wlscirep_modified}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multirow, booktabs, tabularx, longtable}
\usepackage{multirow, makecell}
\usepackage{xurl}
\usepackage{booktabs}
\usepackage{xfp} 
\usepackage{color}
\usepackage{xcolor}
% \usepackage[dvipsnames,table]{xcolor}
\usepackage{multirow, makecell}
\usepackage{tikz}
\usepackage{tabularray}
\usepackage{textcomp,gensymb}
\RequirePackage[labelfont=bf, labelsep=period]{caption}
\usepackage{caption}
\usepackage{tabularray}

% Add longtable and xcolor packages and define a color
\definecolor{white}{HTML}{FFFFFF} 

% tabularray's internal package is recommended for improved formatting, including vertical bars 
\UseTblrLibrary{booktabs}

% ---------------------------------------------------
% Add the word "Supplementary" just before the word "Table" in "longtblr"
% Define and setup templates
\DefTblrTemplate{caption}{supplementary}{
  \DefTblrTemplate{caption-tag}{supplementary}{Supplementary Table \thetable}%
  \DefTblrTemplate{caption-sep}{supplementary}{.}%
  \centering
  \UseTblrTemplate{caption-tag}{supplementary}%
  \UseTblrTemplate{caption-sep}{supplementary}
  \UseTblrTemplate{caption-text}{default}\par
}
\DefTblrTemplate{firsthead}{supplementary}{\UseTblrTemplate{caption}{supplementary}}
\DefTblrTemplate{middlehead}{supplementary}{\UseTblrTemplate{caption}{supplementary}}
\DefTblrTemplate{lasthead}{supplementary}{\UseTblrTemplate{caption}{supplementary}}
% Apply templates%
\NewTblrTheme{supplementary}{
  \SetTblrStyle{caption-tag}{font=\bfseries}
  \SetTblrTemplate{firsthead}{supplementary}
  \SetTblrTemplate{middlehead}{supplementary}
  \SetTblrTemplate{lasthead}{supplementary}
}
% Define and apply caption template in regular tables
\DeclareCaptionFormat{bfdot}{\textbf{#1}.~#3}
\captionsetup[table]{format=bfdot}
% ---------------------------------------------------

\title{Supplementary Information for...}
\author[1]{Luke}
\affil[1]{University of }





\begin{document}
\maketitle


\section*{Supplementary Text}
\subsection*{Notes about ...}
This is about...



\begin{table}[ht]
\centering
\begin{tabular}{|l|l|l|}
\hline
Condition & n & p \\
\hline
A & 5 & 0.1 \\
\hline
B & 10 & 0.01 \\
\hline
\end{tabular}
\caption{\label{tab:first_table}Legend (350 words max). Example legend text.}
\end{table}


\rowcolors{1}{white}{white}



\NewTblrTheme{fancy}{
    \SetTblrStyle{caption-tag}{font=\bfseries}
    }


\begin{longtblr}[  theme=supplementary, \caption{\label{tab:second_table}Legend (350 words max). Example legend text.},]
        {
            colspec={m{0.9cm} m{0.1cm} m{0.6cm} m{1cm} m{3cm} m{7.3cm} m{1.5cm}},
            column{6}={preto={\minipage{\linewidth}}, appto={\endminipage}},
            row{1}={font=\bfseries}, 
            row{2,5,7-8,11-13,20-26,30,33-34,36,39-40,42}={bg=white},
            hline{1,Z}=0.8pt, hline{2}=0.4pt, 
            hline{4,8,10,12-13,15-19,21-26,28-29,32,34,38,40}=dotted, 
            hline{3,5-7,9,11,14,20,27,30-31,33,35,36-37,39,41,42-43}=solid,
            rowhead=1
        }

        Day
        &
        & Month
        & Hours
        & Event
        & Description
        & Further Info
        \\
        %-------------------------------------------------
        Friday
        & $6$
        & February
        & 08 $-$ 19
        & Musical festival
        & 
        Something here ...
        & Multiple 
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 8 
        & \SetCell[r=2]{l} February
        & 08
        & Birthday
        & On Saturdays...
        & Multiple 
        \\
        &
        &
        & 9
        & Local Cup \newline
        & Soemthing here...
        & Single
        \\
        % -------------------------------------------------
    \end{longtblr}



\end{document}

在此处输入图片描述

  1. wlscirep_modified.cls
%
% An unofficial LaTeX class for Scientific Report articles.
%
% Copyright Overleaf (WriteLaTeX) 2016.
%
% Based on the SelfArx document class.
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{wlscirep}[08/08/2020, v1.4]
\RequirePackage[utf8]{inputenc}
\RequirePackage[english]{babel}
\RequirePackage{ifthen}
\RequirePackage{calc}
\AtEndOfClass{\RequirePackage{microtype}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions*
\LoadClass{article}
\RequirePackage{amsmath,amsfonts,amssymb}
\RequirePackage{mathptmx}   % Loads the Times-Roman Math Fonts
\RequirePackage{helvet}
\RequirePackage{courier}
\RequirePackage{ifpdf}
\RequirePackage{graphicx,xcolor}
\RequirePackage{booktabs}


% Modification 1
% to use "\raggedright\arraybackslash"
% https://tex.stackexchange.com/questions/35348/errors-with-ragged-right-justification-in-tables/35350#35350
\RequirePackage{array}

% to add the option "[H]" in "\begin{figure}[H]"
% https://www.overleaf.com/learn/latex/Errors/LaTeX_Error:_Unknown_float_option_%60H'
\RequirePackage{float}


% Settings for the author block
\RequirePackage{authblk}
\setlength{\affilsep}{1.5em}
\renewcommand\Authfont{\fontsize{12}{12}\usefont{OT1}{phv}{b}{n}}
\renewcommand\Affilfont{\fontsize{10}{12}\usefont{OT1}{phv}{m}{n}}

\RequirePackage[left=2cm,%
                right=2cm,%
                top=2.25cm,%
                bottom=2.25cm,%
                headheight=12pt,%
                letterpaper]{geometry}%
                
\RequirePackage[labelfont={bf,sf},%
                labelsep=period,%
                justification=raggedright]{caption}


% Modification 2
% Hyperref + \url: long URL with dashes won't break
% https://tex.stackexchange.com/questions/49788/hyperref-url-long-url-with-dashes-wont-break
\usepackage[hyphens]{url}

% Modification 3
\RequirePackage[colorlinks=true, allcolors=blue]{hyperref}
% \RequirePackage[colorlinks=true, allcolors=black]{hyperref}


% Set up of the bibliography style
% Modification 4
\bibliographystyle{naturemag-doi}
              
%
% headers and footers
%
\RequirePackage{fancyhdr}  % custom headers/footers
\RequirePackage{lastpage}  % Number of pages in the document
\pagestyle{fancy}          % Enables the custom headers/footers
% Headers
\lhead{}%
\chead{}%
\rhead{}%
% Footers
\lfoot{}%
\cfoot{}%
\rfoot{\small\sffamily\bfseries\thepage/\pageref{LastPage}}%
\renewcommand{\headrulewidth}{0pt}% % No header rule
\renewcommand{\footrulewidth}{0pt}% % No footer rule

%
% section/subsection/paragraph set-up
%
\RequirePackage[explicit]{titlesec}
\titleformat{\section}
  {\color{color1}\large\sffamily\bfseries}
  {\thesection}
  {0.5em}
  {#1}
  []
\titleformat{name=\section,numberless}
  {\color{color1}\large\sffamily\bfseries}
  {}
  {0em}
  {#1}
  []  
\titleformat{\subsection}
  {\sffamily\bfseries}
  {\thesubsection}
  {0.5em}
  {#1}
  []
\titleformat{\subsubsection}
  {\sffamily\small\bfseries\itshape}
  {\thesubsubsection}
  {0.5em}
  {#1}
  []    
\titleformat{\paragraph}[runin]
  {\sffamily\small\bfseries}
  {}
  {0em}
  {#1} 
\titlespacing*{\section}{0pc}{3ex \@plus4pt \@minus3pt}{5pt}
\titlespacing*{\subsection}{0pc}{2.5ex \@plus3pt \@minus2pt}{0pt}
\titlespacing*{\subsubsection}{0pc}{2ex \@plus2.5pt \@minus1.5pt}{0pt}
\titlespacing*{\paragraph}{0pc}{1.5ex \@plus2pt \@minus1pt}{10pt}

%
% tableofcontents set-up
%
\usepackage{titletoc}
\contentsmargin{0cm}
\titlecontents{section}[\tocsep]
  {\addvspace{4pt}\small\bfseries\sffamily}
  {\contentslabel[\thecontentslabel]{\tocsep}}
  {}
  {\hfill\thecontentspage}
  []
\titlecontents{subsection}[\tocsep]
  {\addvspace{2pt}\small\sffamily}
  {\contentslabel[\thecontentslabel]{\tocsep}}
  {}
  {\ \titlerule*[.5pc]{.}\ \thecontentspage}
  []
\titlecontents*{subsubsection}[\tocsep]
  {\footnotesize\sffamily}
  {}
  {}
  {}
  [\ \textbullet\ ]  
  
\RequirePackage{enumitem}
%\setlist{nolistsep} % Uncomment to remove spacing between items in lists (enumerate, itemize)

% Remove brackets from numbering in List of References
\renewcommand{\@biblabel}[1]{\bfseries\color{color1}#1.}

%
% article meta data
%
\newcommand{\keywords}[1]{\def\@keywords{#1}}

\def\xabstract{abstract}
\long\def\abstract#1\end#2{\def\two{#2}\ifx\two\xabstract 
\long\gdef\theabstract{\ignorespaces#1}
\def\go{\end{abstract}}\else
\typeout{^^J^^J PLEASE DO NOT USE ANY \string\begin\space \string\end^^J
COMMANDS WITHIN ABSTRACT^^J^^J}#1\end{#2}
\gdef\theabstract{\vskip12pt BADLY FORMED ABSTRACT: PLEASE DO
NOT USE {\tt\string\begin...\string\end} COMMANDS WITHIN
THE ABSTRACT\vskip12pt}\let\go\relax\fi
\go}

%
% custom title page 
%
\renewcommand{\@maketitle}{%
{%
\thispagestyle{empty}%
\vskip-36pt%
{\raggedright\sffamily\bfseries\fontsize{20}{25}\selectfont \@title\par}%
\vskip10pt
{\raggedright\sffamily\fontsize{12}{16}\selectfont  \@author\par}
\vskip18pt%
{%
\noindent
% Modification 5
% remove the "ABSTRACT" command
% {
% % \parbox{\dimexpr\linewidth-2\fboxsep\relax}{\color{color1}\large\sffamily\textbf{ABSTRACT}}
% }
}%
% \vskip10pt
{%
\noindent
\colorbox{color2}{%
\parbox{\dimexpr\linewidth-2\fboxsep\relax}{%
% Modification 6
% remove the "ABSTRACT" command
% \sffamily\small\textbf\\\theabstract
}%
}%
% \vskip18pt%
% \noindent
% \parbox{\dimexpr\linewidth-2\fboxsep\relax}{%
% {\color{color1}\keywordname\hspace*{1em}} \@keywords%
%}%
}%
\vskip25pt%
}%
}%
%-----------------------------------------------
\setlength{\columnsep}{0.55cm} % Distance between the two columns of text 
\setlength{\fboxrule}{0.75pt} % Width of the border around the abstract

\definecolor{color1}{RGB}{0,0,0} % Color of section headings
\definecolor{color2}{gray}{1} % Color of the box behind the abstract
\newcommand{\keywordname}{Keywords:} % Defines the keywords heading name

\newlength{\tocsep} 
\setlength\tocsep{1.5pc} % Sets the indentation of the sections in the table of contents
\setcounter{tocdepth}{3} % Show only three levels in the table of contents section: sections, subsections and subsubsections

\usepackage{lipsum} % Required to insert dummy text
%-----------------------------------------------
\let\oldbibliography\thebibliography
\renewcommand{\thebibliography}[1]{%
\addcontentsline{toc}{section}{\hspace*{-\tocsep}\refname}%
\oldbibliography{#1}%
\setlength\itemsep{0pt}%
}
% Modification 7
%% Automatically abbreviate journal names
%% \RequirePackage{jabbrv}

% Modification 8
\usepackage{nameref}
\usepackage{blindtext}

% Modification 9
% Hyperlinking
\RequirePackage[colorlinks=true, allcolors=blue]{hyperref}


% Modification 10
\usepackage[nameinlink,noabbrev,capitalise]{cleveref}
\Crefname{figure}{Fig.}{Figs.}
\newcommand\crefrangeconjunction{--}   
\crefname{subsection}{Subsection}{Subsections}

% Modification 11
% https://tex.stackexchange.com/questions/44115/how-can-i-change-figure-caption-label
\makeatletter
\renewcommand{\fnum@figure}{Supplementary \figurename~\thefigure}
\renewcommand{\fnum@table}{Supplementary \tablename~\thetable}
\makeatother

% Modification 12
\newcommand{\Tau}{\mathrm{T}}
\usepackage{mathtools}
    
% Modification 13
% https://tug.org/pipermail/texhax/2003-August/000768.html
\newcommand{\sgn}{\mathop{\mathrm{\emph{sgn}}}}

% Modification 14
% from: pnas-new.cls
\RequirePackage[numbers,sort&compress,merge,round]{natbib}

% Modification 15
\newcommand{\quotes}[1]{``#1''}
  1. latexmkrc
$sub_doc_output = 'output-subdoc';

@sub_doc_options = ();

push @sub_doc_options, '-pdf'; # Use pdflatex for compilation of external documents.
# Replace '-pdf' by '-pdfdvi', 'pdfxe', or 'pdflua' if needed.

push @file_not_found, '^No file\\s*(.+)\s*$';

add_cus_dep( 'tex', 'aux', 0, 'makeexternaldocument' );
sub makeexternaldocument {
    if ( $root_filename ne $_[0] )  {
        my ($base_name, $path) = fileparse( $_[0] );
        pushd $path;
        my $return = system "latexmk",
                            @sub_doc_options,
                            "-aux-directory=$sub_doc_output",
                            "-output-directory=$sub_doc_output",
                            $base_name;
        if ( ($sub_doc_output ne ' ') && ($sub_doc_output ne '.') ) {

             rdb_add_generated( "$sub_doc_output/$base_name.aux" );
             copy "$sub_doc_output/$base_name.aux", ".";
        }
        popd;
        return $return;
   }
}

相关内容