Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm hoping for some guidance on why LaTeX isn't properly referencing this table.

\begin{table}[ht] 
\caption*{Table 2 \\ Number and Percentage}\label{tab:table2} 
\centering
\begin{tabular}{rrrrrr}
\hline
 & \# & \# & \# & \% & \% \\ 
  \hline
  A  & 446 & 105 & 42 & 23.54 & 9.42 \\ 
  B  & 389 & 6 & 69 & 1.54 & 17.74 \\ 
  C  & 355 & 8 & 79 & 2.25 & 22.25 \\ 
  D  & 343 & 21 & 107 & 6.12 & 31.20 \\ 
  \hline
\end{tabular}
\end{table}

In Table~\ref{tab:table2} ...

I've tried compiling multiple times and moving the label inside the caption, but neither of those has worked; I still get "In Table ??" as output. Why might this be happening? Thanks for any help!

share|improve this question
    
This works fine for me. Why are you manually captioning the table as "Table 2" inside of the \caption? This is what the command \caption is for; it automatically does these sorts of things. It might be helpful if you turn this into a complete minimal (non-)working example (MWE), in case any packages that you might be loading are the culprit. Also, welcome to TeX.SX! –  Adam Liter Mar 22 at 20:27
    
Are you loading the caption package (i.e., \usepackage{caption})? –  Adam Liter Mar 22 at 20:34
    
Yes to the caption package. It was the first (and so far only) way I found to put "Table 2:" and the name on two separate lines and to remove the colon. I just tried taking out and that solved the problem; is there a way I can keep that formatting, though? Thank you for the tips! –  user3447259 Mar 22 at 20:39
1  
\caption* does not update a counter so does not set a referencable value. You need to use `\caption. But please always post complete documents that reproduce the problem, not just fragments as here. –  David Carlisle Mar 22 at 20:40
    
Please edit your question to reflect what you're actually asking. Also, making this a complete MWE would be helpful, too. Anyway, I've provided an answer. –  Adam Liter Mar 22 at 20:43

1 Answer 1

As @DavidCarlisle notes in the comments, \caption* does not update a counter, so there is nothing for \label to label.

The caption documentation says (p. 17):

The longtable package defines the command \caption* which typesets the caption without label and without entry in the list of tables. [. . .] The caption package offers this feature, too, so you can use this command now within every floating environment [emphasis added]

To achieve the format that you want (as you noted in the comments), you can just make use of caption's \captionsetup.

Also, I've taken the liberty of using booktabs in the following MWE. You might want to use this package in order to typeset nicer tables. See the documentation for some tips on typesetting tables. In brief, the package provides \toprule, \bottomrule, and \midrule, which are nicer than \hline.

\documentclass{article}

\usepackage{caption}
\captionsetup[table]{
    labelsep=newline,
    justification=centering
    }

\usepackage{booktabs} % for nicer looking tables

\begin{document}

\begin{table}[ht] 
\caption{Number and Percentage}\label{tab:table2} 
\centering
\begin{tabular}{rrrrrr}
\toprule
 & \# & \# & \# & \% & \% \\ 
  \midrule
  A  & 446 & 105 & 42 & 23.54 & 9.42 \\ 
  B  & 389 & 6 & 69 & 1.54 & 17.74 \\ 
  C  & 355 & 8 & 79 & 2.25 & 22.25 \\ 
  D  & 343 & 21 & 107 & 6.12 & 31.20 \\ 
  \bottomrule
\end{tabular}
\end{table}

In Table~\ref{tab:table2} ...

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.