I'm using pgfplots (with the excellent matlab2tikz), pgfplotstable and subcaptionbox together, and for some inexplicable reason (at least to me), the command \pgfplotsforeachungrouped seems to break the labels of \subcaptionbox - namely, the labels get turned from (a) into (2subfigure).
I've tried to keep the MWE short, but I wanted to include a snippet of the use case why I want this particular combination of commands (which isn't too far out of the ordinary, I'd say), based on the answer https://tex.stackexchange.com/a/34045/42225.
Commenting out the \pgfplotsforeachungrouped-command removes (most of) the formatting of my table, but then the \subcaptionbox-labels work again (commenting out the content of the command has no effect).
\documentclass{scrbook}
\usepackage{filecontents}
\usepackage{graphicx}
\usepackage{caption}
\usepackage[hypcap=true,justification=centering]{subcaption} % replacement for subfigure (obsolete) and subfig (out-of-date)
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{tikzscale}
\newlength{\plotsize}
\newcommand{\findmax}[3]{% tex.stackexchange.com/a/34045/42225
\pgfplotstablevertcat{\datatable}{#1}
\pgfplotstablecreatecol[
create col/expr={%
\pgfplotstablerow
}]{rownumber}\datatable
\pgfplotstablesort[sort key={#2},sort cmp={float >}]{\sorted}{\datatable}%
\pgfplotstablegetelem{0}{rownumber}\of{\sorted}%
\pgfmathtruncatemacro#3{\pgfplotsretval}
\pgfplotstableclear{\datatable}
}
\pgfplotstableset{
highlight row max/.code 2 args={% tex.stackexchange.com/a/34045/42225
\pgfmathtruncatemacro\rowindex{#2-1}
\pgfplotstabletranspose{\transposed}{#1}
\findmax{\transposed}{\rowindex}{\maxval}
\edef\setstyles{\noexpand\pgfplotstableset{
every row \rowindex\space column \maxval\noexpand/.style={
postproc cell content/.append style={
/pgfplots/table/@cell content/.add={$\noexpand\bf}{$}
},
}
}
}\setstyles
}
}
\pgfplotstableset{%
every head row/.style={font=\sffamily,before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}
}
%%% Commenting this out puts the subfigure labels back in order
\pgfplotsforeachungrouped \alph in {0.9,1,1.1,1.2,1.5,1.75,2}{% tex.stackexchange.com/a/207996/42225
\pgfplotstableset{
columns/a\alph/.estyle={
multiply by=100,fixed,precision=1,zerofill,column name={$\alpha=\alph$},
postproc cell content/.append style={/pgfplots/table/@cell content/.add={}{$\%$}}
}
}
}
\pgfplotstableread{% dummy row so that row/col number from "highlight row max" are correct
dummy a0.9 a1 a1.1 a1.2 a1.5 a1.75 a2
0 0.8628 0.8544 0.8567 0.8305 0.7798 0.6812 0.6204
0 0.8300 0.8233 0.8407 0.8376 0.7853 0.7032 0.6371
0 0.8215 0.8442 0.8391 0.8475 0.7886 0.7166 0.6405
0 0.8224 0.8631 0.8470 0.8514 0.7924 0.7364 0.6503
0 0.8317 0.8434 0.8394 0.8678 0.7952 0.7408 0.6457
0 0.8332 0.8540 0.8401 0.8284 0.7983 0.7270 0.6584
}\alphadata
\begin{filecontents}{empty.tikz}
\begin{tikzpicture}[trim axis left]
\begin{axis}[%
width=\plotsize,
height=\plotsize,
scale only axis,
xmin=0,
xmax=1,
ymin=0,
ymax=1
]
\end{axis}
\end{tikzpicture}%
\end{filecontents}
\begin{document}
\setcounter{chapter}{1}
\begin{table}
\centering
\pgfplotstabletypeset[
highlight row max={\alphadata}{1},
highlight row max={\alphadata}{2},
highlight row max={\alphadata}{3},
highlight row max={\alphadata}{4},
highlight row max={\alphadata}{5},
highlight row max={\alphadata}{6},
create on use/j/.style={create col/expr={\pgfplotstablerow}},% need to create column separately, as it would be the row max otherwise
columns/j/.style={int detect,column name=$j$},
columns={j,a0.9,a1,a1.1,a1.2,a1.5,a1.75,a2}
]\alphadata
\caption{Caption}
\end{table}
\setlength{\plotsize}{0.45\linewidth}
\begin{figure}
{%\hfill%
\subcaptionbox{One}{%
\includegraphics[width=\plotsize]{empty.tikz}
}%
\hfill%
\subcaptionbox{Two}{%
\includegraphics[width=\plotsize]{empty.tikz}
}%
%\hfill%
}
\caption{Caption}
\end{figure}
\end{document}

\pgfplotsinvokeforeach{...}and replace\alphwith#1– percusse Nov 13 '15 at 01:44