Perhaps this will get you closer to what you want.
The general syntax for the \multicolumn
command is
\multicolumn{<number of columns to span>}{<alignment>}{<content>}
You do not specify which columns it spans, just the number of columns to span. As such, the total number of columns spanned and otherwise used needs to be consistent throughout the table
. So, because you wanted 14
columns, you need all of the 2
s and other columns to add up to 14.
Note that the code below results in a very Overfull hbox
and runs off the page- there are a few ugly ways to fix this, such as changing the font size, or perhaps putting it in a resizebox
, but perhaps the best way would be to chop the table
into 2; of course, that's up to you.
\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\begin{document}
\noindent\pgfplotstabletypeset[
every head row/.style={%
before row={\toprule%
NM & NM
&\multicolumn{2}{c}{32-2 LS}
&\multicolumn{2}{c}{128-4 LS}
&\multicolumn{2}{c}{256-8 LS}
&\multicolumn{2}{c}{32-4}
&\multicolumn{2}{c}{128-4}
&\multicolumn{2}{c}{256-8}\\\midrule},
},
every last row/.style={after row=\bottomrule},
string type,
]
{
%sample data
bur26a 26 94.6513 0.9995 145.6622 0.9999 202.7375 1.0000 1.4381 0.9707 2.0208 0.9770 2.9439 0.9786
chr25a 25 84.5684 0.8296 131.5305 0.8881 183.0491 0.9012 1.4192 0.3110 1.9670 0.3369 2.8968 0.3530
}
\end{document}
Following the comments, and the updated MWE in the comments
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage[paperwidth=50cm,paperheight=5cm]{geometry}
\begin{document}
\noindent\pgfplotstabletypeset[
every head row/.style={%
before row={\toprule%
&
& \multicolumn{2}{c}{time avg}
& \multicolumn{2}{c}{quality avg}
& \multicolumn{2}{c}{quality avg}
& \multicolumn{2}{c}{quality avg}
& \multicolumn{2}{c}{quality avg}
& \multicolumn{2}{c}{quality avg}\\
NM & NM
&\multicolumn{2}{c}{32-2 LS}
&\multicolumn{2}{c}{128-4 LS}
&\multicolumn{2}{c}{256-8 LS}
&\multicolumn{2}{c}{32-4}
&\multicolumn{2}{c}{128-4}
&\multicolumn{2}{c}{256-8}\\\midrule},
},
every last row/.style={after row=\bottomrule},
string type,
]
{
%sample data
bur26a 26 94.6513 0.9995 145.6622 0.9999 202.7375 1.0000 1.4381 0.9707 2.0208 0.9770 2.9439 0.9786
chr25a 25 84.5684 0.8296 131.5305 0.8881 183.0491 0.9012 1.4192 0.3110 1.9670 0.3369 2.8968 0.3530
}
\end{document}
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
If you know the name or the number of the column you can specify only that property and the rest will still assume
c
so you don't need the number of columns.