This is a follow up question to How can multiple pgfplotstable columns be used in a legend?
I tried the minimal working example from there and replaced one of the Column names with
{$R_0 = \SI{10}{\kilo\ohm}$}
like this:
\documentclass[]{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepgfplotslibrary{groupplots}
\pgfplotsset{% global config
compat=newest,
every minor tick={very thin, gray},
minor tick num=4,
enlargelimits=0.02,
group style={
columns=2,
xlabels at=edge bottom,
ylabels at=edge left},
every axis legend/.append style={
legend cell align=left,
legend columns=4
}
}
\pgfplotstableread{
Time {Model A} {Model G} {$R_0 = \SI{10}{\kilo\ohm}$}
0 1 1 1
1 1 2 2
2 2 3 3
3 3 4 4
4 5 5 8
5 8 6 10
6 13 7 16
}\modeltable
\pgfplotstableread{
Time {Data 1} {Data 2}
0 1.3 2.3
1 2.6 3.6
2 3.8 4.8
3 7.9 5.9
4 6.3 7.3
5 7.5 6.5
6 9.0 8.9
}\datatable
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
xlabel={Time},
ylabel={Amplitude},
every axis title shift=0,
legend to name=grouplegend,
legend style={/tikz/every even column/.append style={column sep=0.5cm}}
]
\pgfplotsinvokeforeach{1,2}{%
\nextgroupplot[title=Data $#1$]
% Models
\foreach \y in {1, 2, 3} {
\addplot [smooth, dashed, color=DarkRed]
table[x index=0, y index=\y] {\modeltable};
\pgfplotstablegetcolumnnamebyindex{\y}\of{\modeltable}\to{\colname}
\addlegendentryexpanded{\colname}
}
% Data
\addplot [only marks, mark=o]
table[x index=0, y index=#1] {\datatable};
\addlegendentry {Data}
}
\end{groupplot}
\node (dummytitle) at ($(group c1r1.north)!0.5!(group c2r1.north)$)
[above]{};
\node (title) at (dummytitle.north)
[above, yshift=\pgfkeysvalueof{/pgfplots/every axis title shift}]
{Experimental Data};
\node (legend) at ($(group c1r1.south)!0.5!(group c2r1.south)$)
[below, yshift=-2\pgfkeysvalueof{/pgfplots/every axis title shift}]
{\ref{grouplegend}};
\end{tikzpicture}
\end{document}
However, this does not compile.
First error in the log is :
)) ! Undefined control sequence. $R_0 = \SI {10}{\kilo \ohm }$ l.33 }\modeltable
With a couple of after effects. It only does not work when I put the math string in the pgfplottable. Elsewhere in the document it works as expected.
So I figure the pgfplots parser cannot handle column names containing latex commands and/or math mode ?
\pgfplotstableset{columns/R0/.style={column name={$R_0 = \SI{10}{\kilo\ohm}$}}}but it only affects\pgfplotstabletypeset, not the legend. – John Kormylo Dec 05 '19 at 14:46