Show me a solution
This is "a" solution that uses row no 0
as the header. (usually the header is row no -1
). So PgfplotsTable will no longer put the entries inside \csname
. Notice that you need to reset the style for row no 0
if you assign some style for some columns.
\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\usepgflibrary{decorations.fractals}
\begin{document}
\pgfplotstabletypeset[
string type,col sep=&,row sep=\\,
header=false,
every head row/.style={output empty row},
every row no 0/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
]{
\LaTeX & \textit{italic} & \textcolor{orange}{orange} & \reflectbox{reflect} & $e^{i\pi}+1=0$ & \tikz\draw[decoration=Koch snowflake]decorate{decorate{decorate{decorate{(0,0)--(1,0)}}}}; \\
Lorem & ipsum & dolor & sit & amet & consectetur \\
adipisicing & elit & sed & do & eiusmod & tempor \\
}
\end{document}
Combining with cell-processing (update)
There are ≥3 stages of cell-processing. Perhaps typeset cell
is the latest one. (It is even too late to be a processing because there is nothing to do with the literal content then.) Anyway, these keys will probably work as usual.
\pgfplotstabletypeset[
string type,col sep=&,row sep=\\,
header=false,
every head row/.style={output empty row},
every row no 0/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
/pgfplots/table/typeset cell/.code={
\ifnum\pgfplotstablerow=0
\ifnum\pgfplotstablecol=\pgfplotstablecols
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\bfseries\color{orange}#1\\}
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\bfseries\color{orange}#1&}
\fi
\else
\ifnum\pgfplotstablecol=\pgfplotstablecols
\pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\\}
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{#1&}
\fi
\fi
},
]{
\LaTeX & \textit{italic} & \textcolor{red}{R}\textcolor{green}{G}\textcolor{blue}{B} & \reflectbox{reflect} & $e^{i\pi}+1=0$ & \tikz\draw[decoration=Koch snowflake]decorate{decorate{decorate{decorate{(0,0)--(1,0)}}}}; \\
Lorem & ipsum & dolor & sit & amet & consectetur \\
adipisicing & elit & sed & do & eiusmod & tempor \\
}
Show me the official Solution
Same output as before
\pgfplotstabletypeset[
string type,col sep=&,row sep=\\,
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/LaTeX/.style ={column name=\LaTeX},
columns/italic/.style ={column name=\textit{italic}},
columns/orange/.style ={column name=\textcolor{orange}{orange}},
columns/reflect/.style ={column name=\reflectbox{reflect}},
columns/eipi+1/.style ={column name={$e^{i\pi}+1=0$}},
columns/Koch snowflake/.style={column name={\tikz\draw[decoration=Koch snowflake]decorate{decorate{decorate{decorate{(0,0)--(1,0)}}}};}},
]{
LaTeX & itslic & orange & reflect & eipi+1 & Koch snowflake \\
Lorem & ipsum & dolor & sit & amet & consectetur \\
adipisicing & elit & sed & do & eiusmod & tempor \\
}
Show me the reason
Turns out that this is a basic TeX phenomenon which is totally reasonable but no one will ever, logically, think about it. In the following example, I tried to pack \ttfamily
into the name of a control sequence.
\documentclass{minimal}
\begin{document}
\expandafter\let\csname\ttfamily test\endcsname\relax
\end{document}
Then
\ttfamily
is expanded;
- a
\protect
is unveiled;
- TeX read
\protect
before \endcsname
and complained.
./236210 copy.tex:7: Missing \endcsname inserted.
<to be read again>
\protect
l.7 \expandafter\let\csname\ttfamily
test\endcsname\relax
?
(\protect
is \relax
, it cannot be part of csname. Otherwise it is logically contradictive, right?)
Back to pgfplotstable
. This package did plenty of magics and inevitably it put the entry inside a csname. Then BOOM: Since \test
led to \texttt
to \ttfamily
and to \protect
, TeX complained!
So the next question may be whether I can replace \newcommand
by \edef
? For instance
\xdef\test{{\ttfamily test}}
The answer is still NO but for different reason. In fact, due to the design of font-switches, there is internally something like
\xdef \font@name {\curr@fontshape}
But since there is another \edef
outside, the following line is executed
\xdef \OT1/cmr/m/n/10 {\OT1/cmr/m/n/10 }
So Once you apply \test
... BOOM.
The following paraphrase even gives another error.
\xdef\test{\textit{test}}
Conclusion: Never rely on any specific package for, especially, tables.
Best Answer
The One And Only Tabular Layout Package
You are asking for a package to improve the way to lay out your tabulars. On the German list TEX-D-L recently somebody required help to display data in a special way, depending whether the integer inside a cell differs from a standard value and Herbert Voss came up with a very nice and short solution:
Nice, isn't it?
People need very different layouts inside tabulars. They vary much more than the layout of ordinary text does.
So the package that serves your needs won't help others much. So please, give us some examples of the tabulars you'd like to create. Maybe someone here can provide some kind of shortcut.