General ⇒ How to cross-refer to objects in another file?
How to cross-refer to objects in another file?
I have put my figures and tables in different files (.tex file) separate from the document file. In each file, I have labeled the figures and tables (with \label). As I use kile, I have added these files to the relevant project. However, when referring to these objects with \ref, the reference is undefined. How can I make them recognised in other files?
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to cross-refer to objects in another file?
Best regards
Thorsten¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
How to cross-refer to objects in another file?
./Fig.tex:1:\include cannot be nested. \include{header.tex}
Code: Select all
\newcommand*\mycaption[2]{\caption[#1]{#1 #2}}
\newenvironment{narrow}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}}%
\item[]}{\end{list}}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: How to cross-refer to objects in another file?
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
How to cross-refer to objects in another file?
./try.tex:6: Reference `fig:try' on page 1 undefined on input line 6.
try.tex:
Code: Select all
\documentclass[titlepage,12pt,twoside,a4paper]{report}
\usepackage[pdftex]{color,graphicx}
\begin{document}
%\include{image}
My figure is Figure\ref{fig:try}.
\end{document}
Code: Select all
\begin{figure}[h]
\centering
\includegraphics[scale = 2]{try.png}
\caption{This is an image.}
\label{fig:try}
\end{figure}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to cross-refer to objects in another file?
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
How to cross-refer to objects in another file?
My figure is Figure 1.
Code: Select all
\documentclass[titlepage,12pt,twoside,a4paper]{report}
\usepackage[pdftex]{color,graphicx}
\begin{document}
\input{image}
My figure is Figure\ref{fig:try}.
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to cross-refer to objects in another file?
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
How to cross-refer to objects in another file?
Now to print figures and tables as separate files, I realized that they should be defined in a \documentclass and all necessary packages and macros should be defined in each file. There is no elegant way to declare or define these packages and macros (sent previously) once and share them between all figures and tables files?
Code: Select all
\documentclass[titlepage,12pt,twoside,a4paper]{report}
\usepackage[pdftex]{color,graphicx}
\begin{document}
\begin{figure}[h]
\centering
\includegraphics[scale = 2]{try.png}
\caption{This is an image.}
\label{fig:try}
\end{figure}
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: How to cross-refer to objects in another file?
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10