0

Is it possible to include the whole content of the table and figure in another tex file?

Let's say we have A.tex

\documentclass{article}
\begin{document}

write something here.

\begin{table}[tbp]
    \caption{a}
    {
        \begin{tabular*}{\columnwidth}{l@{\extracolsep{\fill}}rrr}
            \toprule
            {test} & {test} & {test} & {test} \\
            \midrule
            {test} & {test} & {test} & {test} \\
            \bottomrule
        \end{tabular*}
    }
    \label{tab:test}
\end{table}

\begin{figure}[tbp]\centering
    \includegraphics[]{test_fig.pdf} 
    \caption{}\label{fig:test}
\end{figure}

\end{document}

And I want to include the tab:test and fig:test in B.tex with the following code:

\documentclass{article}
\usepackage{xr}
\externaldocument[A-][docA.pdf]
\begin{document}
  Tab.~\ref{A-tab:test})
  Fig.~\ref{A-fig:test})
\end{document}

This only get the index of the table and figure like Tab. 2 and Fig. 10. Is it able to import both the contents and the indexes of the table and fig in B.tex? That is, the indexes should still be the same as those A.tex.

4
  • xr "[...] implements a system for eXternal References" nothing more nothing less. If you want to have the code in your document, you have to copy it in or do some gymnastics
    – DG'
    Mar 8, 2023 at 8:53
  • 1
    One way to do this is by saving your table and figure in separate .tex files and using \input{yourtable} or \input{yourfigure} in your main .tex file. Is this what you were looking for?
    – scd
    Mar 8, 2023 at 11:23
  • @DG' Got it. I'll have a look at the link. Thanks for your kind help.
    – yangtzech
    Mar 8, 2023 at 12:31
  • @scd \input{the figure tex file} results in different indexes for the figure. However, I am writing B.tex (a report) based on A.tex by referring. So, the indexes have to be the same.
    – yangtzech
    Mar 8, 2023 at 12:34

0

You must log in to answer this question.

Browse other questions tagged .