1

I have such text table:

Descriptive statistics
=================================================================
Statistic     N  Mean St. Dev.  Min  Pctl(25) Median Pctl(75) Max
-----------------------------------------------------------------
MAE          540 2.1    1.2     0.5    1.0     1.8     2.9    4.4
RMSE         540 2.3    1.1     0.6    1.3     2.2     3.3    4.4
MAE (Top-5)  540 0.4    0.9    0.000  0.004    0.01    0.1    4.0
RMSE (Top-5) 540 0.4    0.9    0.001  0.004    0.01    0.2    4.0
-----------------------------------------------------------------

and I would like to reference to this table via standard \ref{} command. Is it possible? How should I modify my text (table) into regular table?

3
  • Does With the basic label/ref mechanism provided by captions in float-environments answer your question? If not, why not? Do you want to conform the tabular material to look good, or do you want to leave it as is?
    – Johannes_B
    Commented Apr 19, 2015 at 11:52
  • Yes, I can leave it as it is, only what I need is to create a reference to this table from text. Where did you find this question? Google doesn't know it.
    – jnemecz
    Commented Apr 19, 2015 at 11:54
  • Related/possible duplicate Understanding how references and labels work
    – Johannes_B
    Commented Apr 19, 2015 at 12:04

3 Answers 3

2

I will assume that the tabular material is already in a tabular, or similar, environment. In that case, you can achieve your objective as follows:

  • Place the tabular environment inside a table environment

  • Add a \caption instruction, e.g.,

    \caption{Descriptive Statistics}
    
  • Add a \label{...} instruction after the \caption instruction (but before \end{table}

A minimalist example:

....

\begin{table}
\caption{Descriptive Statistics}
\label{tab:desc_stats}
\centering
\begin{tabular}
...
\end{tabular}
\end{table}

...
2

A proper table is a bit to wide for the standard text block.

If there really is no need to transform the tabular material, you can output it verbatim.

\documentclass{article}
\usepackage{blindtext}%optional
\usepackage{caption}%optional
\usepackage{booktabs}%optional
\captionsetup[table]{position=above}
\usepackage{siunitx}%optional
\usepackage{hyperref}%optional
\begin{document}
As can be seen in table~\ref{tab:statistics}, \blindtext
\begin{table}
    \caption{Descriptive statistics}
    \label{tab:statistics}
    \begin{tabular}{lcS[table-format=1.1]
S[table-format=1.1]
S[table-format=1.3]
S[table-format=1.3]
S[table-format=1.2]
S[table-format=1.1]
S[table-format=1.1]
}
    \toprule
    {Statistic}    & {N}   & {Mean} & {St. Dev.} & {Min}   & {Pctl(25)} & {Median} & {Pctl(75)} & {Max}\\
    \midrule
        MAE          & 540 & 2.1  & 1.2      & 0.5   & 1.0      & 1.8    & 2.9      & 4.4\\
        RMSE         & 540 & 2.3  & 1.1      & 0.6   & 1.3      & 2.2    & 3.3      & 4.4\\
        MAE (Top-5)  & 540 & 0.4  & 0.9      & 0.000 & 0.004    & 0.01   & 0.1      & 4.0\\
        RMSE (Top-5) & 540 & 0.4  & 0.9      & 0.001 & 0.004    & 0.01   & 0.2      & 4.0\\
        \bottomrule
    \end{tabular}
\end{table}

As can be seen in \autoref{tab:statisticsVerbatim}, \blindtext
\begin{table}[btp]
        \caption{Descriptive statistics}
    \label{tab:statisticsVerbatim}
    \begin{verbatim}
    =================================================================
    Statistic     N  Mean St. Dev.  Min  Pctl(25) Median Pctl(75) Max
    -----------------------------------------------------------------
    MAE          540 2.1    1.2     0.5    1.0     1.8     2.9    4.4
    RMSE         540 2.3    1.1     0.6    1.3     2.2     3.3    4.4
    MAE (Top-5)  540 0.4    0.9    0.000  0.004    0.01    0.1    4.0
    RMSE (Top-5) 540 0.4    0.9    0.001  0.004    0.01    0.2    4.0
    -----------------------------------------------------------------
    \end{verbatim}
\end{table}

\end{document}
3
  • Have you used some processor to format text table into LaTex format or did you done it manually?
    – jnemecz
    Commented Apr 19, 2015 at 12:27
  • @user1315357 Manually. 3 minutes work.
    – Johannes_B
    Commented Apr 19, 2015 at 12:28
  • To make the tabular material fit, width-wise, inside the text block, one could set \tabcolsep to a very small value (say, 0.1pt) and employ a tabular* environment, setting its overall width to \textwidth and using the @{\extracolsep{\fill}} device to make LaTeX figure out the right amount of intercolumn whitespace. :-)
    – Mico
    Commented Apr 19, 2015 at 14:04
0

Since you don't like to actually use a table environment, but want to use a reference to as well as a caption of a table, then \caption package is what you are after. You can write your table in whatever format you want. Then you can reference it as follows:

\documentclass{article}
\usepackage{caption}
\begin{document}

{\obeyspaces\ttfamily\small
\captionof{table}{Descriptive statistics}
\label{tab:stat}
\noindent\rule{.95\linewidth}{2pt}\\
Statistic     N   Mean  St.Dev. Min  Pctl(25)  Median  Pctl(75) Max\\
\noindent\rule{.95\linewidth}{1pt}\\
MAE          540   2.1    1.2   0.5     1.0      1.8      2.9    4.4\\
RMSE         540   2.3    1.1   0.6     1.3      2.2      3.3    4.4\\
MAE (Top-5)  540   0.4    0.9   0.000   0.004    0.01     0.1    4.0\\
RMSE (Top-5) 540   0.4    0.9   0.001   0.004    0.01     0.2    4.0\\
\noindent\rule{.95\linewidth}{1pt}\\
}

In Table~\ref{tab:stat}, we observe that ...
\end{document}

enter image description here

2
  • That setup allows the caption to be torn apart from the table, better put them in a minipage.
    – Johannes_B
    Commented Apr 19, 2015 at 12:33
  • @Johannes_B Just embraced them between two braces.
    – AboAmmar
    Commented Apr 19, 2015 at 14:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .