3

I have referenced an appendix table in the main text. Depending on where I put the label, I either

  1. Get an error message saying that the reference is undefined (and the main text reads 'Table ??')
  2. Reference the table using the name of the whole section, so it is 'Table B' not 'Table B1' (the table appears in section B of the appendix).

Can anyone let me know what I am doing wrong? Here is a MWE which illustrates the first case ('Table ??'):


\documentclass[12pt]{article}

\usepackage{amssymb, hyperref, amsmath,amsfonts, bm, eurosym,geometry,ulem,graphicx,caption,mathtools,natbib, xcolor,setspace,comment,footmisc,caption,pdflscape,subfigure,array, parskip, bbm, csquotes, multirow, booktabs,caption}

\usepackage[flushleft]{threeparttable}

\usepackage[toc,page]{appendix}

\graphicspath{ {./images/} }

\newcommand{\red}[1]{{\color{red} #1}}
\newcommand{\blue}[1]{{\color{blue} #1}}

\geometry{left=1.0in,right=1.0in,top=1.0in,bottom=1.0in}

\begin{document}

Here is some text. I will try to reference Table \ref{overview}


\clearpage

\setlength{\bibhang}{0pt}
\bibliographystyle{apalike}
\bibliography{bibliography.bib}

\newpage

\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}

\setcounter{figure}{0}
\renewcommand{\thefigure}{A\arabic{figure}}

\begin{appendices}

\section{Proofs} \label{proofs}

Here are some proofs

\newpage

\section{Additional tables and figures} \label{tables_figures}

\setcounter{table}{0}
\renewcommand{\thetable}{B\arabic{table}}

\setcounter{figure}{0}
\renewcommand{\thefigure}{B\arabic{figure}}

\begin{center}
\begin{threeparttable}[h]
\begin{tabular}{cclcc}
\hline
\caption{Overview}\label{overview}
Moose & Rabbit & \hspace{3em}Deer      & Elephant & Mango \\ \hline
1                & Yes             & a & 10              & 18                    \\
2                & Yes             & b & 10              & 18                    \\
3                & No              & c & 10              & 10                    \\
4                & No              & d & 10              & 10                    \\
5                & No              & e           & 9               & 10                    \\
6                & No              & e           & 9               & 10                    \\ \hline
\end{tabular}

\begin{tablenotes}
\footnotesize
\item \hspace{-0.2em}\textit{Notes}: Here are some notes...
\end{tablenotes}
\end{threeparttable}
\end{center}


\end{appendices}


\end{document}

Here is is a MWE which illustrates the second case ('Table B'):


\documentclass[12pt]{article}

\usepackage{amssymb, hyperref, amsmath,amsfonts, bm, eurosym,geometry,ulem,graphicx,caption,mathtools,natbib, xcolor,setspace,comment,footmisc,caption,pdflscape,subfigure,array, parskip, bbm, csquotes, multirow, booktabs,caption}

\usepackage[flushleft]{threeparttable}

\usepackage[toc,page]{appendix}

\graphicspath{ {./images/} }

\newcommand{\red}[1]{{\color{red} #1}}
\newcommand{\blue}[1]{{\color{blue} #1}}

\geometry{left=1.0in,right=1.0in,top=1.0in,bottom=1.0in}

\begin{document}

Here is some text. I will try to reference Table \ref{overview}


\clearpage

\setlength{\bibhang}{0pt}
\bibliographystyle{apalike}
\bibliography{bibliography.bib}

\newpage

\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}

\setcounter{figure}{0}
\renewcommand{\thefigure}{A\arabic{figure}}

\begin{appendices}

\section{Proofs} \label{proofs}

Here are some proofs

\newpage

\section{Additional tables and figures} \label{tables_figures}

\setcounter{table}{0}
\renewcommand{\thetable}{B\arabic{table}}

\setcounter{figure}{0}
\renewcommand{\thefigure}{B\arabic{figure}}

\begin{center}
\begin{threeparttable}[h]
\begin{tabular}{cclcc}
\hline
\caption{Overview}
Moose & Rabbit & \hspace{3em}Deer      & Elephant & Mango \\ \hline
1                & Yes             & a & 10              & 18                    \\
2                & Yes             & b & 10              & 18                    \\
3                & No              & c & 10              & 10                    \\
4                & No              & d & 10              & 10                    \\
5                & No              & e           & 9               & 10                    \\
6                & No              & e           & 9               & 10                    \\ \hline
\end{tabular}
\begin{tablenotes}
\footnotesize
\item \hspace{-0.2em}\textit{Notes}: Here are some notes...
\end{tablenotes}
\end{threeparttable}
\label{overview}
\end{center}


\end{appendices}


\end{document}

2
  • You should be getting an error message about the \caption directive not occurring inside a LaTeX "float" -- the main examples of which are table and figure. Also, \caption directives are never allowed inside tabular environments. You need to (a) embed the threeparttable material in a table environment and (b) place the \caption{Overview} instruction immediately after \begin{threeparttable} and before \begin{tabular}.
    – Mico
    Jun 27 at 19:02
  • 1
    @Mico thanks, I actually just figured that out! Will delete Q
    – afreelunch
    Jun 27 at 19:06

1 Answer 1

7

LaTeX must be issueing two separate error messages related to the table.

  • \caption directives are not allowed outside of LaTeX floats (such as table and figure).

  • \caption directives are not allowed inside tabular environments.

The remedy? (a) encase the threeparttable material in a table environment. (b) Remove the \caption directive from its current place and insert it right after \begin{threeparttable} instead.

enter image description here

\documentclass[12pt]{article}
%% I've left some comments next to some of your preamble directives
\usepackage{amssymb, 
  hyperref, 
  %amsmath,  % is loaded automatically by mathtools
  %amsfonts, % is loaded automatically by amssymb
  bm, eurosym, geometry, ulem, graphicx, caption, 
  mathtools, natbib, xcolor, setspace, comment, 
  footmisc, 
  %%caption, % don't load packages twice
  pdflscape,
  %%subfigure,  % obsolete and incompatible with caption package
  array, parskip, bbm, csquotes, multirow, booktabs %,
  %%caption  % and most definitely don't load a package three times!
  }
\captionsetup{skip=0.333\baselineskip} % <-- new (default is '1\baselineskip')
\hypersetup{colorlinks=true, allcolors=blue} % <-- new

\usepackage[flushleft]{threeparttable}

\usepackage[toc,page]{appendix}
\graphicspath{ {./images/} }
\newcommand{\red}[1]{{\color{red} #1}}
\newcommand{\blue}[1]{{\color{blue} #1}}
%% "margin=1in" is a lot easier than "left=1.0in,right=1.0in,top=1.0in,bottom=1.0in"
\geometry{margin=1in}


\begin{document}

\begin{appendices}
\renewcommand{\thetable}{\thesection\arabic{table}}
\renewcommand{\thefigure}{\thesection\arabic{figure}}

\section{Proofs} \label{proofs}

Here are some proofs

\newpage

\section{Additional tables and figures} \label{tables_figures}

\begin{table}[ht] % <-- new
\centering % <-- new
\begin{threeparttable}
\caption{Overview}  % <-- new location
\label{overview}
\begin{tabular}{@{} cclcc @{}}
\toprule
Moose & Rabbit & Deer & Elephant & Mango \\ 
\midrule
1     & Yes    & a    & 10       & 18    \\
2     & Yes    & b    & 10       & 18    \\
3     & No     & c    & 10       & 10    \\
4     & No     & d    & 10       & 10    \\
5     & No     & e    &  9       & 10    \\
6     & No     & e    &  9       & 10    \\ 
\bottomrule
\end{tabular}

\footnotesize
\begin{tablenotes}
\item[]\hspace{-0.2em}\textit{Notes}: Here are some notes \dots

\end{tablenotes}
\end{threeparttable}
\end{table} % <-- new

A cross-reference to \autoref{overview}.

\end{appendices}
\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.