6

in this MWE you can see/explore (hopefully, as it does not work for me) that \ref{tab:2} produces the right label but if you click on it, it will lead you to the \label{tab:1}. \usepackage{appendix} and \begin{appendix} ... \end{appendix} doesn't helped and as I assume I'm using the \label at the right position.

EDIT: The solution putting the \numbering behind the hyperref worked well(!), but another error occured in combination with subfigures. The label does not fit anymore, if the \numbering is placed before the include of the subfigure package. I´ve heard that hyperref should be the last included package for some reasons, but as solution for this error: Can I just place the \usepackage{subfigure} after hyperref and \numbering?

\documentclass[12pt,a4paper]{scrartcl}
\KOMAoptions{captions=tableheading}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{thumbpdf}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{color}
\usepackage[
  colorlinks,
  allcolors = blue,
]{hyperref}
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

\begin{document}
    \section{sec one}
    \begin{table}[!h]
        \caption{Tab one}
        \label{tab:1}
        \centering
        \renewcommand{\arraystretch}{1.2}
        \begin{tabular}{l|c|c}
            1 & 2 & 3\\
        \end{tabular}
    \end{table}
    MWE, more in the appendix, tab \ref{tab:2}
    \section{sec two}
    \begin{figure}[!h]
        \centering
        \subfigure[left fig \label{fig:left}]{\includegraphics[width=0.49\linewidth]{default.png}}
        \subfigure[right fig \label{fig:right}]{\includegraphics[width=0.49\linewidth]{default.png}}
    \caption{left and right fig}
    \end{figure}
    Next Problem: subfigures \ref{fig:left}
    \appendix
    \clearpage
    \section{appendix}
    \subsection{to sec one}
    \begin{table}[!h]
        \caption{Tab two}
        \label{tab:2}
        \centering
        \renewcommand{\arraystretch}{1.2}
        \begin{tabular}{l|c|c}
            1 & 2 & 3\\
        \end{tabular}
    \end{table}
\end{document}
  • The subfigure package has been deprecated for a long time. Don't use it. Instead, use either the subfig or the subcaption package. – Mico Aug 26 '15 at 8:15
  • Since the subfig package is known for several issues regarding hyperref, I would use the subcaption package. (I'm sorry for the shameless self-advertising here but the broken hyperref support of subfig was the main reason why I decided to write the subcaption package.) – Axel Sommerfeldt Sep 15 '15 at 21:00
10

hyperref supports \numberwithin, but only if it awares of it. Therefore, \numberwithin should be used after package hyperref.

Further remarks:

  • Option allcolors simplifies the setting of the colors to one color with option colorlinks.

  • Package hyperref detects driver pdftex automatically, it does not need to be set explicitly.

  • KOMAScript option captions=tableheading fixes the skip settings around table captions, which are used above the table. Thus, the empty line hack can be removed.

Full example:

\documentclass[12pt,a4paper]{scrartcl}
\KOMAoptions{captions=tableheading}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{thumbpdf}
\usepackage{color}
\usepackage[
  colorlinks,
  allcolors = blue,
]{hyperref}
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

\begin{document}
    \section{sec one}
    \begin{table}[!h]
        \caption{Tab one}
        \label{tab:1}
        \centering
        \renewcommand{\arraystretch}{1.2}
        \begin{tabular}{l|c|c}
            1 & 2 & 3\\
        \end{tabular}
    \end{table}
    MWE, more in the appendix, tab \ref{tab:2}

    \appendix
    \clearpage
    \section{appendix}
    \subsection{to sec one}
    \begin{table}[!h]
        \caption{Tab two}
        \label{tab:2}
        \centering
        \renewcommand{\arraystretch}{1.2}
        \begin{tabular}{l|c|c}
            1 & 2 & 3\\
        \end{tabular}
    \end{table}
\end{document}
  • thank you, that worked well! but now another issue appeared using the packages grapicx and subfigures, I´ve edited my MWE – NN123 Aug 26 '15 at 8:03
5

pdftex is warning you in the log that the destination anchors are not unique

l.43         \caption{Tab two}
                              pdfTeX warning (ext4): destination with the same 
identifier (name{table.1}) has been already used, duplicate ignored
<to be read again> 

As Heiko wrote in this case the easiest is to move the \numberwithin commands and let hyperref take care of it. A manual solution is to redefine \theHtable so that gives an unique representation.

Also avoid to insert spaces with \ \\ after a caption. Such spaces can be changed by options and setting lengths.

\documentclass[12pt,a4paper,
               captions=tableabove,  %better spacing after table captions
               ]{scrartcl}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}


\usepackage{thumbpdf}
\usepackage{color}
\usepackage[
  colorlinks,
  citecolor = {blue},
  linkcolor = {blue},
  urlcolor  = {blue}]{hyperref}

\renewcommand\theHtable{\thesection.\thetable} 

\begin{document}
    \section{sec one}
    \begin{table}[!h]
        \caption{Tab one}
        \label{tab:1}
        \centering
        \renewcommand{\arraystretch}{1.2}
        \begin{tabular}{l|c|c}
            1 & 2 & 3\\
        \end{tabular}
    \end{table}
    MWE, more in the appendix, tab \ref{tab:2}

    \appendix
    \clearpage
    \section{appendix}
    \subsection{to sec one}
    \begin{table}[!h]
        \caption{Tab two}
        \label{tab:2}
        \centering
        \renewcommand{\arraystretch}{1.2}
        \begin{tabular}{l|c|c}
            1 & 2 & 3\\
        \end{tabular}
    \end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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