3

How can I use pgfplotstable with multirow to create a table with a column in which every cell spans 3 rows.

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{multirow}

\begin{filecontents}{table.csv}
A,B,C
1,1,200
 ,3,300
 ,5,400
2,1,150
 ,3,250
 ,5,350
\end{filecontents}

\pgfplotstableread[col sep=comma]{table.csv}\tabledata

\begin{document}
\begin{table}
    \centering
    % ???
\end{table}
\end{document}

Should result in a table that looks like:

┌───┬───┬─────┐
│ A │ B │  C  │
├───┼───┼─────┤
│   │ 1 │ 200 │
│ 1 │ 3 │ 300 │
│   │ 5 │ 400 │
│   │ 1 │ 150 │
│ 2 │ 3 │ 250 │
│   │ 5 │ 350 │
└───┴───┴─────┘

1 Answer 1

6

You can check the row number modulo 3 and do things accordingly.

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{multirow}
\pgfplotstableread[col sep=comma]{
A,B,C
1,1,200
 ,3,300
 ,5,400
2,1,150
 ,3,250
 ,5,350
}\tabledata

\begin{document}
\begin{table}
    \centering
    \pgfplotstabletypeset[
    columns/A/.style={
        assign cell content/.code={%
        \pgfmathparse{int(Mod(\pgfplotstablerow,3)}%
        \ifnum\pgfmathresult=0%
            \pgfkeyssetvalue{/pgfplots/table/@cell content}%
            {\multirow{3}{*}{##1}}%
        \fi%
        },
    },
    ]{\tabledata}
\end{table}
\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 .