1

I am writing report of results. Each model has its own section with results stored in table, where each table has the same number of columns and consists of one row of titles and one row of actual results:

\begin{table}[ht]
\centering
\begin{tabular}{|rrrrrrrrrr|}
  \hline
model & acc & bacc & TPR & TNR & FAR & prec0 & prec1 & $\kappa$ & auc \\ 
  \hline
model_name & 80.16 & 82.16 & 67.76 & 96.56 & 3.44 & 69.38 & 96.30 & 61.39 & 82.16 \\ 
   \hline
\end{tabular}
\end{table}

and in the end of the chapter I would like to summarize all results from such a table into one big table, where one row will correspond to one model. However I want to do that automatically, because if I find a mistake in a model and recompute it, I dont want to change the values in both tables, but just in this simple one. I am writting the report in overleaf. Any ideas?

2
  • Hi, welcome, I see someone has left a possible solution below. Just a quick note that I've removed the Overleaf tag, since Overleaf isn't relevant to this particular question. In this particular question, the solution is the same whether you use Overleaf or any other TeX editor and distribution on your own computer. Commented Nov 15, 2019 at 14:57
  • 1
    Thanks, I did not know in advance whether the solution will be general or overleaf-specific, so I used it. But now removed overleaf tag makes sense.
    – pikachu
    Commented Nov 15, 2019 at 14:59

2 Answers 2

1

Here's an automated implementation:

\documentclass{article}

\newcommand{\commonheader}{%
  \begin{tabular}{|rrrrrrrrrr|}
  \hline
  model & acc & bacc & TPR & TNR & FAR & prec0 & prec1 & $\kappa$ & auc \\ 
  \hline
}
\newtoks\tablerows
\newcommand{\maketable}[1]{%
  \commonheader
  #1 \\
  \hline
  \end{tabular}
  \global\tablerows=\expandafter{\the\tablerows#1\\}
}
\newcommand{\fulltable}{%
  \commonheader
  \the\tablerows
  \hline
  \end{tabular}
  \global\tablerows{}%
}

\begin{document}

\begin{table}[!htp]
\centering

\maketable{model\_name & 80.16 & 82.16 & 67.76 & 96.56 & 3.44 & 69.38 & 96.30 & 61.39 & 82.16}

\caption{First table}

\end{table}

\begin{table}[!htp]
\centering

\maketable{model\_name & 90.16 & 92.16 & 77.76 & 16.56 & 4.44 & 69.38 & 96.30 & 61.39 & 82.16}

\caption{Second table}

\end{table}

\begin{table}[!htp]
\centering

\fulltable

\caption{Full table}

\end{table}

\end{document}

enter image description here

After using \fulltable, the token register is cleared, so you can start afresh in the next chapter.

2
  • if you want to copy one cell content to another table cell, how to do it?
    – Nathan G
    Commented Aug 26, 2023 at 15:42
  • @NathanB The simplest way is to define a new command for the cell contents.
    – egreg
    Commented Aug 26, 2023 at 21:01
0

This stores all the data into a macro using pgfplotstable, then only displays some of the rows as selected. The header row is always shown. Note: rows are numbered starting with 0.

\documentclass{article}
\usepackage{pgfplotstable}

\pgfplotstableread[col sep=&, row sep=\\]{
model & acc & bacc & TPR & TNR & FAR & prec0 & prec1 & kappa & auc \\
model\_one & 80.16 & 82.16 & 67.76 & 96.56 & 3.44 & 69.38 & 96.30 & 61.39 & 82.16 \\
model\_two & 80.16 & 82.16 & 67.76 & 96.56 & 3.44 & 69.38 & 96.30 & 61.39 & 82.16 \\
}{\mydata}

\pgfplotstableset{
  columns/model/.style={ column type=|l, string type},
  columns/acc/.style={column type=l},
  columns/bacc/.style={column type=l},
  columns/TPR/.style={column type=l},
  columns/TNR/.style={column type=l},
  columns/FAR/.style={column type=l},
  columns/prec0/.style={column type=l},
  columns/prec1/.style={column type=l},
  columns/kappa/.style={column type=l, column name=$\kappa$},
  columns/auc/.style={column type=l|},
  before row=\hline,
  every last row/.style={after row=\hline},
}

\begin{document}
\begin{table}[t]
\centering
\pgfplotstabletypeset[skip rows between index={1}{100}]{\mydata}
\end{table}

\begin{table}[t]
\centering
\pgfplotstabletypeset[skip rows between index={0}{1}]{\mydata}
\end{table}

\begin{table}[t!]
\centering
\pgfplotstabletypeset{\mydata}
\end{table}

\null\vfill

\end{document}

demo

You must log in to answer this question.

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