# TeXStudio - Cross-reference in case of multiple files

I have a master document and for each chapter a separate file like:

main.tex

% preamble etc.

\input{chapter1}
\input{chapter2}
\input{chapter3}
% and so on


chapter1.tex

% Some figure with a label, tex code not shown, just the label
\label{fig:chicken}
% Some figure with a label, tex code not shown, just the label
\label{fig:monkey}

This two-legs animal is a chicken as shown in \cref{fig:chicken} % OK! Works within the same chapter! fig. 1


chapter2.tex

Here I like to refer to \ref{fig:monkey} % results in ??


Referring to a label in another chapter results in a double question mark (I did compile multiple times). LyX has the option to set a master document for each "included" tex-file. Document > Settings > Select default master document.

How can I do this in TeXstudio? I've already set main.tex as the master document but can't find a way to refer from its childs back to the master document like in LyX.

It's important to add the \label{} after or inside \caption{}

main.tex

\documentclass{scrartcl}
\usepackage{cleveref}
\usepackage[demo]{graphicx}
\usepackage[justification=RaggedRight, singlelinecheck=false]{caption}

\begin{document}

\input{chapter1}
\input{chapter2}

\end{document}


chapter1.tex

\chapter{Chapter 1}

\begin{figure}[h!]
\caption{ Test}
\label{fig:chicken}
\includegraphics{chicken}
\end{figure}


chapter2.tex

\chapter{Chapter 2}

Here I like to refer to \cref{fig:chicken}


Output

Here I like to refer to fig. 1.1

• I discovered that the package cleveref should be included after hyperref and if used, amsmath, thanks to your example SLx64. Thanks a lot! – RisingSun May 25 '14 at 15:11
• Yes you have to include the hyperref package bevor cleveref if you want to use it. If it works for you, please accept my answer. – SLx64 May 25 '14 at 15:24
• I'd love too, needs reputation of 15 for that, it seems. – RisingSun May 25 '14 at 23:45
• There is a check mark under the two arrows. :) – SLx64 May 26 '14 at 5:05
• Oh, thanks! SLx64. Have a nice day. – RisingSun May 26 '14 at 11:00