\section{Grouped rows and best-value marking}
\key{\gradgroup{title}} inserts a full-width group heading. Each group needs at
least one data row. Groups do not alter scales or participate in ranking.
Group color defaults to gradbarsTrack; an empty value removes it. Group sep
defaults to 4pt. All rule styles support groups.
\begin{demo}{Ties, second-best values and lower-is-better metrics}
\begin{center}
\begin{gradtable}[align=c,header align=c,text width=30mm,
  graphic width=38mm,label width=12mm,group sep=4pt]
  \gradcolumn{method}{Method}
  \gradcolumn[type=bar,mark=both,
    options={max=100,precision=1}]{score}{Score}
  \gradcolumn[type=number,mark=both,width=24mm,
    options={better=lower,precision=1}]{time}{Time / s}
  \gradgroup{Baselines}
  \gradrow{A,82.4,12.8}
  \gradrow{B,90.2,10.5}
  \gradgroup{Improved methods}
  \gradrow{C,90.2,9.6}
  \gradrow{D,86.7,9.6}
  \gradrow{E,NA,NA}
\end{gradtable}
\end{center}
\end{demo}
Best values are bold and second-best values are underlined. Mark can be none
(default), best or both, for number, bar and bullet columns. Ranking covers the
whole table, across groups and pages. Use \key{better=higher} or \key{better=lower} inside
column options; target-distance and interval-quality ranking are not supported.

Ranking uses raw values before rounding. Equal numbers (including 2 and 2.0)
tie; second best is the next distinct value. NA is excluded and zero participates.
An all-missing column has no marks; an all-equal column has no second best.
Increase precision if rounding hides a distinction. For stacks or trends, add a
separate number column defining the metric to rank. Explain the marking in a caption.

\clearpage


\subsection{Automatic CSV groups and within-group ranks}
\begin{sloppypar}
\key{group by=family} references a declared text column ID, not a CSV header.
Groups follow first occurrence in the CSV and omit groups with no displayed
rows. Within each group, rows retain their global-sort order. Empty text forms
a real group named (ungrouped); group missing label customizes its title.
Literal text NA and configured missing tokens remain separate names. Automatic
groups cannot be combined with manual \key{gradgroup} declarations.
\key{rank scope=group} ranks displayed observations independently in each group;
the default table retains whole-table ranking. Missing numbers are skipped,
zero participates, and ties/second distinct values follow the existing rules.
Manual groups also support group statistics: repeated titles remain separate
groups, and rows preceding the first heading form an implicit unnamed group.
\end{sloppypar}
\begin{demo}{Complete example: algorithm-family comparisons}
\gradbarsloadcsv{families}{docs/data/families.csv}
\begin{center}
\begin{gradtable}[align=c,header align=c,data=families,width=\linewidth,style=academic,theme=teal,
  scale=column,group by=family,rank scope=group,group summary=true,
  sort keys={score/descending,time/ascending}]
  \gradcolumn[source=Method]{method}{Method}
  \gradcolumn[source=Family]{family}{Family}
  \gradcolumn[type=bar,source=Score,mark=both,aggregate=mean]{score}{Score}
  \gradcolumn[type=number,source=Time,mark=both,aggregate=min,
    options={better=lower,precision=0}]{time}{Time / ms}
  \gradsummary{All visible}
\end{gradtable}
\end{center}
\end{demo}
Classic and Neural have mean scores of 82 and 91, with minimum times of 8 and
12. Group headings stay with the first data row; group summaries appear once
with the final group row. Continued pages do not repeat group headings.
Column or explicitly shared scales span all groups to preserve comparisons.
