Table mislabeled as figure

I have an image and a table and they need to appear in the same page. The way I'm doing that right now is by wrapping them both in a figure. The problem I'm having is I'm trying to reference the table and LaTex keeps on labeling it as a figure.

\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[singlelinecheck=false]{caption}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{graphicx}
\graphicspath{ {./images/} }

\begin{document}

stuff stuff \autoref{table:nmr_nitro} blah blah.

\begin{figure}
\includegraphics[scale=0.4]{3-nitrobenzonitrile.png}
\captionof{figure}{3-Nitrobenzonitrile with hydrogens assignments}
\label{figure:nmr_fig_nitro}

\begin{threeparttable}
\captionof{table}{NMR of 3-nitrobenzonitrile}
\label{table:nmr_nitro}

\begin{tabular}{ c c }
\toprule
\textbf{Some Data} & \textbf{Assignment} \\
\midrule
8.542; 2.0 (2H); m;        & A, B \\
7.960; 2.1 (2H); m;        & C, D \\
\bottomrule
\end{tabular}
\end{threeparttable}

\end{figure}

\end{document}


I found two solutions-ish to this problem. The first is to use manual instead of autoref and just manually label all my links. The other is to put \captionsetup{type=table} above my table caption but this seems like a hack. Is there any builtin, smooth way to do this?

This is because you put the table in a figure environment. Since you are already using the caption package, you may e.g. do

\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[singlelinecheck=false]{caption}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{graphicx}
\graphicspath{ {./images/} }

\begin{document}

stuff stuff \autoref{table:nmr_nitro} blah blah.

\noindent
\begin{minipage}{\textwidth}
\centering
\includegraphics[scale=0.4]{example-image-a}
\captionof{figure}{3-Nitrobenzonitrile with hydrogens assignments}
\label{figure:nmr_fig_nitro}

\captionof{table}{NMR of 3-nitrobenzonitrile}
\label{table:nmr_nitro}
\begin{threeparttable}

\begin{tabular}{ c c }
\toprule
\textbf{Some Data} & \textbf{Assignment} \\
\midrule
8.542; 2.0 (2H); m;        & A, B \\
7.960; 2.1 (2H); m;        & C, D \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{minipage}

\end{document}


• This doesnt work because I need the image and the table to be guaranteed to be on the same page. – FailureGod Apr 4 at 5:11
• @FailureGod You can certainly make them appear on one side. The question is if you want them to float or be fixed at a given page. – user121799 Apr 4 at 5:13
• @FailureGod The you could for instance wrap them in a minipage or in a tabular, depending on your layout preferences. – user121799 Apr 4 at 5:27
• I need them to appear at a specific place in text. Like ''' Some text <image and figure> more text ''' where the image and the figure are not broken by a pagebreak. – FailureGod Apr 4 at 5:31
• @FailureGod I added something of that sort. – user121799 Apr 4 at 5:32

I think an easier solution would be to change caption to capt-of:

From:

\usepackage[singlelinecheck=false]{caption}


To:

\usepackage{caption2}
\captionsetup{singlelinecheck=false}

• While this fixs the labeling problem it also prevents me from left aligning the caption. – FailureGod Apr 4 at 16:36
• What about using \usepackage{caption2} followed by \captionsetup{singlelinecheck=false} instead? I think it addresses everything. – Guilherme Silva Apr 5 at 1:36