0

I created a table that represented a 5x5 confusion matrix, and gave it the label tab:shape_confusion. The table is different than a regular table because it uses 10 figures to represent the descriptions of the data. Below is what the final generated table looks like.

enter image description here

However, when I tried both \autoref{tab:shape_confusion} and Table~\ref{tab:shape_confusion} in the text, the output PDF file shows ?? instead of the autogenerated number. I also receive the following warning:

You have referenced something which has not yet been labelled. If you have labelled it already, make sure that what is written inside \ref{...} is the same as what is written inside \label{...}.

The document already has half a dozen other tables that correctly generate their table numbers, and it is only this table that is having this issue. I was editing the table line by line, and discovered that the table number was generating correctly with a few figures, but stops generating the table number after adding more figures.

Below is the entire code of the table causing this issue.

\begin{table}[!ht]
\centering
\caption{Confusion matrix for distinguishing between the 5 hand shapes using shape context.}
\label{tab:shape_confusion}
\begin{tabular}{|c|c|c|c|c|c|}

\hline

&
\multicolumn{5}{c|}{Classified As }\\

\hline

\thead{Hand Shape} &
\includegraphics[scale=0.48]{figures/hand_shape/ok.png} & 
\includegraphics[scale=0.48]{figures/hand_shape/thumbsup.png} & 
\includegraphics[scale=0.48]{figures/hand_shape/hand.png} & 
\includegraphics[scale=0.48]{figures/hand_shape/idp.png} & 
\includegraphics[scale=0.48]{figures/hand_shape/v.png} \\

\hline

\includegraphics[scale=0.48]{figures/hand_shape/ok.png} & 
\cellcolor{Blackone}{\textcolor{white}{95}} &
\cellcolor{Graytwo}{4} &
0 &
\cellcolor{Graytwo}{1} &
0 \\

\hline

\includegraphics[scale=0.48]{figures/hand_shape/thumbsup.png} &
0 &
\cellcolor{Blackone}{\textcolor{white}{98}} &
0 &
\cellcolor{Graytwo}{1} &
\cellcolor{Graytwo}{1} \\

\hline

\includegraphics[scale=0.48]{figures/hand_shape/hand.png} &
\cellcolor{Graytwo}{6} &
0 &
\cellcolor{Blackone}{\textcolor{white}{93}} &
\cellcolor{Graytwo}{1} &
0 \\

\hline

\includegraphics[scale=0.48]{figures/hand_shape/idp.png} &
\cellcolor{Graytwo}{2} &
\cellcolor{Graytwo}{7} &
0 &
\cellcolor{Blackone}{\textcolor{white}{91}} &
0 \\

\hline

\includegraphics[scale=0.48]{figures/hand_shape/v.png} &
\cellcolor{Graytwo}{1} &
\cellcolor{Graytwo}{1} &
0 &
\cellcolor{Graytwo}{1} &
\cellcolor{Blackone}{\textcolor{white}{97}} \\

\hline

\end{tabular}
\end{table}

I was wondering if someone was familiar with this problem and knew how to get the table number properly displayed instead of with "??"?

2
  • 5
    please provide complete but small document with your table which demonstrate your problem. from your code sniped can't be see, what cause your problem. Do you compile twice?
    – Zarko
    Jun 9, 2018 at 17:56
  • Welcome! Try not using a special character in the label, but don't know whether this is a problem or not.
    – cfr
    Jun 10, 2018 at 2:03

1 Answer 1

1

in my test referencing of your table works as expected, i.e. without any errors or warnings. after two (one for referencing is not sufficient) compilation i obtained the following result:

enter image description here

since you didn't provide complete small document with your table, i wrote own with minimal preamble, which provides among others a shorter code for the table and, according to my taste, more nicer table:

\documentclass{article}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage[demo, export]{adjustbox}
\usepackage{etoolbox}

\begin{document}
    \begin{table}[!ht]
\expandafter\patchcmd\csname Gin@ii\endcsname      % https://tex.stackexchange.com/questions/439918/
  {\setkeys {Gin}{#1}}
  {\setkeys {Gin}
      {width=0.12\linewidth,height=0.12\linewidth,  % standard graphicx settings
       valign=c, margin=0pt 6pt 0pt 6pt,#1}         % settings from adjustbox
  }
  {}{}
\centering
\caption{Confusion matrix for distinguishing between the 5 hand shapes using shape context.}
\label{tab:shape_confusion}
\begin{tabular}{|c|c|c|c|c|c|}
    \hline
    &   \multicolumn{5}{c|}{Classified As }             \\
    \hline
Hand Shape
    &   \includegraphics[]{figures/hand_shape/ok.png}
    &   \includegraphics{figures/hand_shape/thumbsup.png}
    &   \includegraphics{figures/hand_shape/hand.png}
    &   \includegraphics{figures/hand_shape/idp.png}
    &   \includegraphics{figures/hand_shape/v.png}      \\
    \hline
\includegraphics{figures/hand_shape/ok.png}
    &   \cellcolor{black!50!blue}{\textcolor{white}{95}}
    &   \cellcolor{gray!30}{4}
    &   0
    &   \cellcolor{gray!30}{1}
    &   0   \\
    \hline
\includegraphics{figures/hand_shape/thumbsup.png}
    &   0
    &   \cellcolor{black!50!blue}{\textcolor{white}{98}}
    &   0
    &   \cellcolor{gray!30}{1}
    &   \cellcolor{gray!30}{1}                          \\
    \hline
\includegraphics{figures/hand_shape/hand.png}
    &   \cellcolor{gray!30}{6}
    &   0
    &   \cellcolor{black!50!blue}{\textcolor{white}{93}}
    &   \cellcolor{gray!30}{1}
    &   0       \\
    \hline
\includegraphics{figures/hand_shape/idp.png}
    &   \cellcolor{gray!30}{2}
    &   \cellcolor{gray!30}{7}
    &   0
    &   \cellcolor{black!50!blue}{\textcolor{white}{91}}
    &   0       \\
    \hline
\includegraphics{figures/hand_shape/v.png}
    &   \cellcolor{gray!30}{1}
    &   \cellcolor{gray!30}{1}
    &   0
    &   \cellcolor{gray!30}{1}
    &   \cellcolor{black!50!blue}{\textcolor{white}{97}} \\
    \hline
\end{tabular}
    \end{table}
see Table \ref{tab:shape_confusion}. as you can see, the reference works properly :-).
\end{document}

note, in real document you had to remove from adjustbox the option demo (it instead real images, which i haven't, generate black boxes). also use cell color as you defined in your document (instead Blackone i use black!50!blue for simpler distinguishing demo images from colored cells).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .