2

I'd like to typeset data in multiple columns below one another. The problem is, if I were to typeset lots of data for relatively few parameters, I'd like to typeset the content on a upright a4 page. In consequence I'd like to stack the columns in the back under the columns in the front. One could use several \pgfplotstypeset commands of course but then, what about the alignment and precise formatting? So this question is about trying to typeset it with one command, if possible. I am sure some of you may find this trivial but I have never used pgfplotstable before so I am a bit baffled.

Specifically I supplied some fake data file data.txt which I would like to typeset in a table with 7 columns.

The typeset table shall have 1 head row. It should have a first column which I want to fill with content myself (which would be AA, BB, CC,... in every fifth row). Then the columns Word--ColHeadAA5 should follow. The content up to this point should be put up top. The data in the remaining columns ColHead1BB-ColHead5BB should be put below that. The columns which get put below shall not include their column headings, only the data. They should of course be put in the columns 3--7, not the first two columns.

It is noteworthy that this is of course an abstract example--one might expand this to plenty more columns "converted" into stacked "rows". I also intend to implement some booktabs formatting if I'll use this.

Is this even possible?

Little extra: between the stacked sets I'd like to have some additional vertical space inserted, something that roughly equals \addlinespace[3pt] of the booktabs-package.

Example picture of what should be typeset

enter image description here

MWE

\documentclass{scrartcl}

\usepackage{pgfplotstable}

\begin{filecontents}{data.txt}
Word,ColHeadAA1,ColHeadAA2,ColHeadAA3,ColHeadAA4,ColHeadAA5,ColHeadBB1,ColHeadBB2,ColHeadBB3,ColHeadBB4,ColHeadBB5
A,17,19,15,17,3,8,14,7,8,14
B,10,8,11,15,10,8,6,13,13,10
C,20,5,16,12,8,5,16,7,14,17
D,14,4,10,14,16,14,5,10,5,11
\end{filecontents}

\pgfplotstableread[col sep=comma]{data.txt}{\mydata}

\begin{document}
\begin{center}
\pgfplotstabletypeset[columns/Word/.style={string type}]{\mydata}
\end{center}
\end{document}
2
  • Either you will need to create a new table which is actually organized the way you want it printed, or you need to extract the contents of the table and create a tabular. Oct 6, 2014 at 14:28
  • @JohnKormylo Actually chose to typeset the table by hand. Will leave this question open though.
    – henry
    Oct 6, 2014 at 19:26

1 Answer 1

1

It's not difficult with \pgfplotstablesave to create to parts of the original table and \pgfplotstablevertcat to vertically concatenate those two parts.

You'll find the details in the comments of my code:

\documentclass{scrartcl}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\pgfplotstableset{
% create aliases for correct merging
    alias/ColHeadAA1/.initial=ColHeadBB1,
    alias/ColHeadAA2/.initial=ColHeadBB2,
    alias/ColHeadAA3/.initial=ColHeadBB3,
    alias/ColHeadAA4/.initial=ColHeadBB4,
    alias/ColHeadAA5/.initial=ColHeadBB5,
% create first column with AA, BB, etc.
    create on use/Something/.style={
        create col/set list={AA,,,,BB,,,,}},
    columns/Something/.style={string type}
}

\begin{filecontents}{data.txt}
Word,ColHeadAA1,ColHeadAA2,ColHeadAA3,ColHeadAA4,ColHeadAA5,ColHeadBB1,ColHeadBB2,ColHeadBB3,ColHeadBB4,ColHeadBB5
A,17,19,15,17,3,8,14,7,8,14
B,10,8,11,15,10,8,6,13,13,10
C,20,5,16,12,8,5,16,7,14,17
D,14,4,10,14,16,14,5,10,5,11
\end{filecontents}

\begin{document}
% Read your table
\pgfplotstableread[
    col sep=comma, 
    ]{data.txt}{\tableall}

% create table A with the fist 5 columns (and Word)
\pgfplotstablesave[
    columns={Word,ColHeadAA1,ColHeadAA2,ColHeadAA3,ColHeadAA4,ColHeadAA5},
    ]{\tableall}{tableA.out}

% create table B with the last 5 columns (and Word)
\pgfplotstablesave[
    columns={Word,ColHeadBB1,ColHeadBB2,ColHeadBB3,ColHeadBB4,ColHeadBB5}
    ]{\tableall}{tableB.out}

% load table A in a new table tablevertcat
\pgfplotstableread{tableA.out}{\tablevertcat}

% append the contents of table B to table A (tablevertcat)
\pgfplotstablevertcat{\tablevertcat}{tableB.out}

% and this is the final result
\begin{center}
\pgfplotstabletypeset[
    columns={Something,Word,ColHeadAA1,ColHeadAA2,ColHeadAA3,ColHeadAA4,ColHeadAA5},
    % add a little space every 4 rows
    every nth row={4}{before row=\addlinespace[4pt]},
    % booktabs rules
    every head row/.style={
        before row=\toprule,
        after row=\midrule
    },
    every last row/.style={
        after row=\bottomrule
    },
    columns/Word/.style={string type},
    % correct column numbers alignment
    multicolumn names,
    columns/ColHeadAA1/.style={string type,column type={S[table-format=2]}},
    columns/ColHeadAA2/.style={string type,column type={S[table-format=2]}},
    columns/ColHeadAA3/.style={string type,column type={S[table-format=2]}},
    columns/ColHeadAA4/.style={string type,column type={S[table-format=2]}},
    columns/ColHeadAA5/.style={string type,column type={S[table-format=2]}},
    ]{\tablevertcat}
\end{center}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .