2

I have a problem using the wrapfigure package. As you'll see in the code example below, when I call \ref{My table} what I get is a reference to the section I am in instead of the table.

\documentclass{article}

\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}

    \section{Section}

    \subsection{Subsection}

    \begin{wraptable}{l}{0pt}
        \begin{tabular}{cccc}
        A & B & C & D \\
        E & F & G &  H\\        
        \end{tabular}
    \label{My table}\caption{This is my table.}
    \end{wraptable}

\textbf{Table \ref{My table} should be called Table 1.}
\lipsum[2]

\end{document}

Reference problem using wrapfig package

Thanks!

lomper
  • 123

1 Answers1

7

As a simple workaround, you can place the label within the caption:

\documentclass{article}

\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}

    \section{Section}

    \subsection{Subsection}

    \begin{wraptable}{l}{0pt}
        \begin{tabular}{cccc}
        A & B & C & D \\
        E & F & G &  H\\        
        \end{tabular}
    \caption{\label{Mytable}This is my table.}
    \end{wraptable}

\textbf{Table \ref{Mytable} should be called Table 1. The text should also begin aligned with the table's top row.}
\lipsum[2]

\end{document}

enter image description here

(don't use spaces in labels)

  • That does work, thanks a lot. Thanks for the tip on spaces :). What is the etiquette though, should I leave it with your comment in case it can help anyone or fix it? – lomper Apr 22 '20 at 16:33
  • 1
    That's not a "workaround" though. It is a rule in LaTeX for all figures and tables: the \label needs to go in or after the caption, because the caption does the numbering.https://tex.stackexchange.com/questions/32325/why-does-an-environments-label-have-to-appear-after-the-caption – Donald Arseneau Apr 24 '20 at 18:47
  • Thanks @DonaldArseneau. How do you choose between tex.stackexchange and stackoverflow when it comes to LaTeX questions? – lomper Apr 27 '20 at 08:01