4

I want a plot and a table to show up together in my document, therefore I used the figure environment, made the plot with tikzpicture, linked to this file, then added the \captionof command and then added the table in tabular environment. In my document refering to the table gives me Abb. instead of Tab.. When using the exact same code in a new document refering to the table by \autoref gives me Tab. as it should. In my document though it says Abb. instead of Tab. but the enumeration follows the one of the Tables, not the figures.

\documentclass[12pt]{article}
\usepackage{hyperref}
\usepackage{capt-of}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\addto\captionsngerman{\def\figurename{Abb.}}
\addto\extrasngerman{\def\figureautorefname{Abb.}}
\addto\extrasngerman{\def\tableautorefname{Tab.}}
\begin{document}
\begin{figure}
\centering
    %Figure
    \begin{tikzpicture}
        \begin{axis}
            \addplot coordinates{(1,1)};
        \end{axis}
    \end{tikzpicture}
    \caption{CAPTION}
    \label{figure}
    %Table
    \captionof{table}{CAPTION\label{tab:LABEL}}
        \begin{tabular}{ccc}
            akbvk & laknflfk& kanfkf  \\
        \end{tabular}
\end{figure}

Refering to the figure (\autoref{figure}) and refering to the table (\autoref*{tab:LABEL})
\end{document}

The code shows a minimal example that works as intended in a new document but inserted into my existing document it suddenly doesn't work. Packages and the \addto commands are the same in both documents. My thesis is 50 pages already strong and neither do I want to publish it nor do you (probably) want to dig in it to find what's wrong, but maybe you have an idea what could be the problem...

Compiled in my document Compiled in a new document

The first picture shows the code, given above, in my document (thesis) the second in the new document.

Edit: I copied all the packages I use in my thesis into the new document and then deleted one package after the other, this way I found out the subfig package causes the error:

\documentclass[12pt]{article}
\usepackage{hyperref}
\usepackage{capt-of}
\usepackage{subfig}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\addto\captionsngerman{\def\figurename{Abb.}}
\addto\extrasngerman{\def\figureautorefname{Abb.}}
\addto\extrasngerman{\def\tableautorefname{Tab.}}
\begin{document}
\begin{figure}
\centering
%Figure
\begin{tikzpicture}
    \begin{axis}
        \addplot coordinates{(1,1)};
    \end{axis}
\end{tikzpicture}
\caption{CAPTION}
\label{figure}
%Table
\captionof{table}{CAPTION\label{tab:LABEL}}
    \begin{tabular}{ccc}
        akbvk & laknflfk& kanfkf  \\
    \end{tabular}
\end{figure}

Refering to the figure (\autoref{figure}) and refering to the table (\autoref*{tab:LABEL})
\end{document}

Since I wouldn't want to miss on subfig, do you know how to bypass the problem?

7
  • 1
    Well, the problem is that precisely the more interesting file shows the feature but you did not post it... I suspect some missing \label after a \captionof command – user31729 Feb 6 '17 at 16:58
  • The code given above gives different results when inserted in my existing document and when inserted in a whole new document (as you can see in the images). If I missed the \label it wouldn't work in either of these documents. So it must have something to do with my document/thesis. Since it's 50 pages strong I don't really know how to post it here, I was just hoping the problem sounds familiar to you. – A. Nel Feb 6 '17 at 17:19
  • Try to reduce your 50 page document to a version that still has the issue, everything else is guessing around – user31729 Feb 6 '17 at 17:23
  • I tried to and copied all the packages I use in my thesis to the new document. After that I had the problem in my new document too. Then I eliminated one package after the other and the problem disappeared when I deleted the package subfig. – A. Nel Feb 6 '17 at 17:33
  • Ah, that's the way to go. Try to load caption-of (or the caption package) after subfig, it should work then even with subfig included – user31729 Feb 6 '17 at 17:36
3

The easiest solution is to put an explicit \captionsetup[type=table] before \captionof{table}{...}.

Apparently, \captionof should not be used in floating environment at all, it seems to grab the wrong \@captype content. In final, this will write a wrong anchor name to the .aux file from which \autoref grabs its information to determine the name.

Perhaps, the grouping together is not the best way at all.

The package cleveref provides correct names, however!

\documentclass[12pt]{article}

\usepackage{capt-of}
\usepackage{subfig}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\usepackage{hyperref}
\addto\captionsngerman{\def\figurename{Abb.}}
\addto\extrasngerman{\def\figureautorefname{Abb.}}
\addto\extrasngerman{\def\tableautorefname{Tab.}}
\begin{document}
\begin{figure}
\centering
%Figure
\begin{tikzpicture}
    \begin{axis}
        \addplot coordinates{(1,1)};
    \end{axis}
\end{tikzpicture}
\caption{CAPTION}
\label{figure}
%Table
\captionsetup{type=table}
\captionof{table}{CAPTION\label{tab:LABEL}}
    \begin{tabular}{ccc}
        akbvk & laknflfk& kanfkf  \\
    \end{tabular}
\end{figure}

Refering to the figure (\autoref{figure}) and refering to the table (\autoref*{tab:LABEL})
\end{document}

enter image description here

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.