Erro \endgroup ausente com ifs aninhados nos cálculos foreach e pgf

Erro \endgroup ausente com ifs aninhados nos cálculos foreach e pgf
\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{float}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{datatool}

\begin{filecontents}{data.dat}
28.7 28.4 43.4
0.2416 0.2415 nan
0.2420 0.2416 nan
0.2421 0.2416 nan
0.2416 0.2422 nan
0.2410 0.2422 nan
35.9 35.6 50.4
0.2695 0.2691 nan
0.2679 0.2691 nan
0.2691 0.2697 nan
0.2691 0.2691 nan
0.2686 0.2694 nan
42.6 42.3 57.4
0.2951 0.2953 nan
0.2950 0.2951 nan
0.2952 0.2956 nan
0.2951 0.2957 nan
0.2951 0.2954 nan
47.2 46.9 61.9
0.3091 0.3104 nan
0.3095 0.3107 nan
0.3106 0.3107 nan
0.3105 0.3110 nan
0.3107 0.3103 nan
51.3 51.1 66.1
0.3234 0.3231 nan
0.3231 0.3235 nan
0.3238 0.3233 nan
0.3229 0.3241 nan
0.3243 0.3230 nan
57.4 57.2 72.3
0.3417 0.3431 nan
0.3426 0.3431 nan
0.3422 0.3437 nan
0.3430 0.3427 nan
0.3429 0.3437 nan
\end{filecontents}

\pgfplotsset{compat=1.14}
\pgfplotstableread{data.dat}\Data

\begin{document}

\begin{table}
\title{Pendulum Data for Steel Ball}
\begin{tabular}{|l|l|l|l|} \hline
$d$ (cm) & $y$ (cm) & $\tau$ (s) & $\tau^2$ (s) \\\hhline{|=|=|=|=|}
\foreach \row in {0,...,35}
{
        \newcount\countuno
        \countuno=\row
        \divide\countuno by 6
        \multiply\countuno by 6
        \ifnum\countuno=\row
                \pgfplotstablegetelem{\row}{2}\of\Data    \pgfmathsetmacro\dval{\pgfplotsretval}
                \pgfplotstablegetelem{\row}{0}\of\Data \pgfmathsetmacro\yval{\pgfplotsretval}
                \multirow{5}{*}{$\pgfmathprintnumber{\dval}$} & \multirow{5}{*}{$\pgfmathprintnumber{\yval}$}
        \else
                \pgfplotstablegetelem{\row}{0}\of\Data \pgfmathsetmacro\tval{\pgfplotsretval}
                \pgfmathsetmacro\tsqrval{\tval ^ 2}
                \advance\countuno by 1
                \ifnum\countuno<\row
                        &
                \fi
                & $\pgfmathprintnumber{\tval}$ & $\pgfmathprintnumber{\tsqrval}$ \\\hline
        \fi
}
\end{tabular}
\end{table}
\end{document}

eu recebo o erro

! Missing \endgroup inserted.
<inserted text> 
                \endgroup
l.83     }

Não vejo onde pode estar o erro. Passei algum tempo mexendo na sintaxe das instruções if, mas elas não parecem estar causando o problema e, até onde eu sei, o loop foreach também parece bom. Possivelmente tem algo a ver com os comandos pgf. Seria realmente incrível se alguém identificasse o problema.

Responder1

Você não pode iniciar o loop em uma célula e terminá-lo em outra.

Uma solução alternativa é construir a tabela na primeira célula e entregá-la toda de uma vez.

Já que sou contra \multirowe prendo tabelas, veja como você pode fazer isso booktabs.

\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\usepackage{amsmath}
\usepackage{booktabs}

\begin{filecontents}{\jobname.dat}
28.7 28.4 43.4
0.2416 0.2415 nan
0.2420 0.2416 nan
0.2421 0.2416 nan
0.2416 0.2422 nan
0.2410 0.2422 nan
35.9 35.6 50.4
0.2695 0.2691 nan
0.2679 0.2691 nan
0.2691 0.2697 nan
0.2691 0.2691 nan
0.2686 0.2694 nan
42.6 42.3 57.4
0.2951 0.2953 nan
0.2950 0.2951 nan
0.2952 0.2956 nan
0.2951 0.2957 nan
0.2951 0.2954 nan
47.2 46.9 61.9
0.3091 0.3104 nan
0.3095 0.3107 nan
0.3106 0.3107 nan
0.3105 0.3110 nan
0.3107 0.3103 nan
51.3 51.1 66.1
0.3234 0.3231 nan
0.3231 0.3235 nan
0.3238 0.3233 nan
0.3229 0.3241 nan
0.3243 0.3230 nan
57.4 57.2 72.3
0.3417 0.3431 nan
0.3426 0.3431 nan
0.3422 0.3437 nan
0.3430 0.3427 nan
0.3429 0.3437 nan
\end{filecontents}

\pgfplotsset{compat=1.14}
\pgfplotstableread{\jobname.dat}\Data

\newcount\countuno

\begin{document}

\begin{table}
\title{Pendulum Data for Steel Ball}
\begin{tabular}{llll}
\toprule
$d$ (cm) & $y$ (cm) & $\tau$ (s) & $\tau^2$ (s) \\
\midrule
\gdef\tablecontents{}%
\foreach \row in {0,...,35}
  {%
   \countuno=\row
   \divide\countuno by 6
   \multiply\countuno by 6
   \ifnum\countuno=\row
     \pgfplotstablegetelem{\row}{2}\of\Data
     \pgfmathsetmacro\dval{\pgfplotsretval}%
     \pgfplotstablegetelem{\row}{0}\of\Data
     \pgfmathsetmacro\yval{\pgfplotsretval}%
     \xdef\tablecontents{%
       \unexpanded\expandafter{\tablecontents}%
       \ifnum\row>0 \noexpand\midrule \fi
       $\noexpand\pgfmathprintnumber{\dval}$ &
       $\noexpand\pgfmathprintnumber{\yval}$
     }%
   \else
     \pgfplotstablegetelem{\row}{0}\of\Data
     \pgfmathsetmacro\tval{\pgfplotsretval}%
     \pgfmathsetmacro\tsqrval{\tval ^ 2}%
     \advance\countuno by 1
     \xdef\tablecontents{%
       \unexpanded\expandafter{\tablecontents}
       \ifnum\countuno<\row &\fi
       & $\noexpand\pgfmathprintnumber{\tval}$
       & $\noexpand\pgfmathprintnumber{\tsqrval}$
       \noexpand\\
     }%
   \fi
  }%
  \tablecontents
  \bottomrule
\end{tabular}
\end{table}
\end{document}

insira a descrição da imagem aqui

informação relacionada