[Tex/LaTex] Keep example number together with floating table

floatslinguexlinguisticsnumberingpage-breaking

I am using the package linguex (for 'linguistic examples') to number the examples in my text, using its command \ex.

I am creating a table that I am numbering with this command \ex.:

\ex. \label{my_table}
\begin{tabular}[t]{l l l l}
Row 1 & Row 2 & Row 3 & Row 4\\
etc.
\end{tabular}

The option [t] for \begin{tabular} is necessary to have the example number be on the same line as the first row in the table.

My table is rather large, so I want to make it a float, so I embed the section above within a {table} environment. When I do this, however, the example number for my table is separated from the table, i.e. there is a page break between them. How can I prevent this?

\ex. \label{my_table}
\begin{table}
\begin{tabular}[t]{l l l l}
Row 1 & Row 2 & Row 3 & Row 4\\
etc.
\end{tabular}
\end{table}

Best Answer

You can't put an ex. into a floating environment, but you can simulate it by manually adding the example number inside the table environment. Depending on where the table floats to it's possible that the numbering might be out of order, but try it and see.

\documentclass{article}
\usepackage{linguex}
\begin{document}
Some text.
\ex. The first example.

\begin{table}[hbt]
\refstepcounter{ExNo}\theExNo\hspace{\Exlabelsep}\label{table}
\begin{tabular}[t]{l l l l}
Row 1 & Row 2 & Row 3 & Row 4\\
Row 1 & Row 2 & Row 3 & Row 4\\
Row 1 & Row 2 & Row 3 & Row 4
\end{tabular}
\end{table}
Some more text. This is a reference to example \ref{table}.
\ex. Another example.

\end{document}
\end{tabular}

Update

Note that the placement of the \label command matters with respect to subsequent reference to it via the \ref command. If the label is placed immediately after the table, it will refer to the table counter, which is not what you want. If you place it after the stepping and displaying of the ExNo counter, it will behave as a reference to the example number, which is what you want.

output of code

Related Question