General ⇒ Problem with cross-references
Problem with cross-references
I don't what could disable the cross-reference. I use the cross-reference correctly to the tables or sections but when I compile, I don't get any error message and the cross-reference doesn't get displayed in the text. Any package loading or definition that might disable the cross-reference?
Thanks
Thanks
NEW: TikZ book now 40% off at Amazon.com for a short time.

Problem with cross-references
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Problem with cross-references
Yes, here it is:
Code: Select all
\documentclass[10pt]{report}
% Load packages
\usepackage{tabularx}
\begin{document}
Ref to tab \ref{tab:tab}.
\par
\begin{table}
\mbox{
\begin{tabular}{|c|c|c|}
\hline \multicolumn{3}{|c|}{My Table}\\ \hline
A1 & B2 & C3 \\ \hline
A2 & ... & .. \\ \hline
A3 & .. & . \\ \hline
\end{tabular}
}
\label{tab:tab}
\end{table}
\end{document}
Problem with cross-references
Hi, inside floating environments (table and figure, and those defined by the user) you need to use the \caption command before the \label command, in order to generate the string that will be picked up by the \ref command:
Compile the document twice.
Code: Select all
\documentclass[10pt]{report}
\usepackage{tabularx}
\usepackage{hyperref}
\begin{document}
Ref to tab \ref{tab:tab}.
\begin{table}
\begin{tabular}{|c|c|c|}
\hline \multicolumn{3}{|c|}{My Table}\\ \hline
A1 & B2 & C3 \\ \hline
A2 & ... & .. \\ \hline
A3 & .. & . \\ \hline
\end{tabular}
\caption{a test table}
\label{tab:tab}
\end{table}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: Problem with cross-references
As you noticed the sentence "Ref to tab" gets displayed after the table but it comes before the table. THis depends on the position of \begin{table}. On the other hand, I can't put \begin{table} inside of \mbox. What would you suggest?
Problem with cross-references
You can control the positioning of floats using the placement specifiers; most of the times you want to use [!ht]; your code would look something like:
Search the board to see how to proceed if you don't want your tables and/or figures to float at all.
Code: Select all
\begin{table}[!ht]
\begin{tabular}{|c|c|c|}
\hline \multicolumn{3}{|c|}{My Table}\\ \hline
A1 & B2 & C3 \\ \hline
A2 & ... & .. \\ \hline
A3 & .. & . \\ \hline
\end{tabular}
\caption{a test table}
\label{tab:tab}
\end{table}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Problem with cross-references
Is it possible to cross-refer to section*? If so, why the name of the section is not displayed?
Code: Select all
\documentclass[10pt]{report}
\begin{document}
refer to the section \ref{sec:my_section}
\section*{my section} \label{sec:my_section}
\end{document}
Problem with cross-references
Using \label and \ref are not meant to be used when you want to refer to the "title" of a section/table/figure but when you want to refer to the "number" of a section/table/figure. Because your section uses a * to drop the numbering, you get nothing in your output.
Compare this with the following example where I deleted the *.
The output is this:
Edit by localghost: Preferably no external links (see Board Rules). Attachments go onto the forum server where possible.
Compare this with the following example where I deleted the *.
Code: Select all
\documentclass[10pt]{report}
\begin{document}
refer to the section \ref{section:my_section}
\section{my section}\label{section:my_section}
\end{document}
Edit by localghost: Preferably no external links (see Board Rules). Attachments go onto the forum server where possible.