Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've already seen these two questions:

Create a contingency table using pgfplotstable and Dec sep align & \multicolumn incompatibility?

and I'm still not able to do what I want. I rarely use tex, and sometimes I need to do tables/figures and I'm not used to it.

I have 14 columns (for now, I'll try to reduce) and I want to group them with multicolums.

The first two columns aren't supposed to be grouped, then all the remaining 12 should be grouped by pairs, so column 3 and 4 should form a multicolumn, 5 and 6, and so on. And each of these pairs, the columns should be named, the first has a name like "time avg" and the second "quality avg".

How do I set where the multicolumn starts or which columns it should group? I can only see a column number parameter, but it never gets specified which columns the multi will group.

The dumb code I have for now is:

\documentclass{standalone}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{booktabs}
\usepackage[paperwidth=50cm,paperheight=\maxdimen]{geometry}
\usepackage{tikz}

\begin{document}



\pgfplotstabletypeset[
 every head row/.style={%
  before row={\toprule 
    & \multicolumn{2}{c}{Data} \\
            & \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}},
    after row=\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}

Needless to say it doesn't even get close to what I want. I even tried to pair the first two columns with a multicolumn with no success.

edit:

after reading (more like trying over and over) some more I kind of got what I want, hacking with "&"'s, but the table needs some improvement, like making the second row columns have the same name.

\documentclass{article}

\usepackage[paperwidth=25cm]{geometry}
\usepackage{booktabs}
\usepackage{pgfplotstable}

\begin{document}

\noindent\pgfplotstabletypeset[
 every head row/.style={
 before row={\toprule
  &
   &\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}
   &},
},
every last row/.style={after row=\bottomrule},
string type,
]
{
Inst n qavg tavg qavg2 tavg2 qavg3 tavg3 qavg4 tavg4 qavg5 tavg5 qavg6 tavg6
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}

Gives me this:

http://i.imgur.com/9e5lu.png

share|improve this question
2  
While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. While solving problems is fun, setting them up is not. Then those trying to help can simply cut and paste your MWE and get started on solving problem. –  Peter Grill Nov 30 '12 at 3:53
add comment

1 Answer

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 2s 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}
share|improve this answer
    
I added the whole code I'm using atm. The hack I found is that geometry package, just resized the paper to a big one. I'll try it now. –  polar Nov 30 '12 at 17:02
    
@polar ok, feel free to follow-up if my answer doesn't resolve the issue :) –  cmhughes Nov 30 '12 at 17:04
    
Aw damn, I forgot to add something to the data. Each column should have a name. Like, on every pair, the first column is called "time avg" and the second "quality avg". These aren't the real names, but something like this. Much like the second and third column from this question: tex.stackexchange.com/questions/62409/… –  polar Nov 30 '12 at 17:07
    
So this means there would be two column rows, the first one has 7 multicolumns, grouping by pairs, and the second row has 14 columns. –  polar Nov 30 '12 at 17:15
    
@polar I've updated my answer- if it's not what you want, meet me in the chat room –  cmhughes Nov 30 '12 at 17:19
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.