[Tex/LaTex] Bad table references with \input{…}

cross-referencinginput

I have been searching a bit, but couldn't find the proper answer to my problem.

I have multiple tables defined for a report. Let's say some tables are presented in the main content of the report and for further clarity, are also defined in the appendix.

Since they are subject to last minute modification, I didn't want to create twice the same tables, so I inserted them with the \input command.

The problem is that when I call \ref, it is the reference of the table in the appendix that is given (ie: A.3 not 1.5).

How could I manage this?

Table definition:

\begin{table}[htbp]
    \centering
    \begin{tabular}{ccc} \hline
    \multicolumn{3}{c}{value test}\\ \hline
    Model & \multicolumn{2}{c}{3D} \\
    $S$ & 102.60 & 66.90 \\
    $S^{macro}$ & $93.43$ & $63.90$\\
    Relative scatter (\%) & $-8.94$ & $-4.48$\\
    \hline
    \end{tabular}
    \caption{$S_{12}$ analysis}
    \label{tab:S12_analysis}
    \end{table}

In the document for example

\begin{document}[report]

Table \ref{tab:S12_analysis}
\input{my_table.tex}

\appendix
Table \ref{tab:S12_analysis}
 \input{my_table.tex}

\end{document}

Best Answer

replace

 \label{tab:S12_analysis}

on your file by \labelthistable

then use

Table \ref{mytableone}
\newcommand\labelthistable{\label{mytable1}}\\input{my_table.tex}

...

\appendix
Table \ref{mynewtable}
\newcommand\labelthistable{\label{mynewtabl1}}\\input{my_table.tex}