Cómo utilizar una tabla en formato de texto como una tabla normal (y una referencia a ella)

Cómo utilizar una tabla en formato de texto como una tabla normal (y una referencia a ella)

Tengo tal tabla de texto:

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
-----------------------------------------------------------------

y me gustaría hacer referencia a esta tabla mediante \ref{}un comando estándar. ¿Es posible? ¿Cómo debo modificar mi texto (tabla) en una tabla normal?

Respuesta1

Asumiré que el material tabular ya se encuentra en un tabularentorno , o similar. En ese caso, puede lograr su objetivo de la siguiente manera:

  • Colocar el tabularentorno dentro de un tableentorno.

  • Agregue una \captioninstrucción, por ejemplo,

    \caption{Descriptive Statistics}
    
  • Agregar una \label{...}instruccióndespuésla \captioninstrucción (pero antes\end{table}

Un ejemplo minimalista:

....

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

...

Respuesta2

Una tabla adecuada es un poco ancha para el bloque de texto estándar.

Si realmente no es necesario transformar el material tabular, puede imprimirlo palabra por palabra.

\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}

Respuesta3

Dado que no le gusta utilizar un tableentorno, pero desea utilizar una referencia y un título de una tabla, entonces \captionlo que busca es paquete. Puedes escribir tu tabla en el formato que quieras. Entonces puedes hacer referencia a él de la siguiente manera:

\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}

ingrese la descripción de la imagen aquí

información relacionada