pgfplotstable: Have every other row be a multicolumn
up vote
0
down vote
favorite
I am trying to make a table using pgfplotstable
, and am having difficulties because the csv
's are jagged. Most rows have 4 columns, as do the headers, but some rows are only 1 column and I would like these 1-cell rows to span the width of the table.
How do I either have pgfplotstable
dynamically create multicolumns depending on the csv, or set every other row to be a multicolumn using data from the csv?
mwe (does not produce the proper layout):
documentclass{article}
usepackage{pgfplotstable,multirow,booktabs}
begin{filecontents}{data.csv}
ColumnHeader1, ColumnHeader2, ColumnHeader3, ColumnHeader4
item1, string1, string2, string3
some-text-goes-here
item2, string1, string2, string3
some-more-text-goes-here
end{filecontents}
begin{document}
pgfplotstabletypeset[
col sep = comma,
column type = l,
string type,
multicolumn names,
every head row/.style={before row=toprule, after row=midrule},
every last row/.style={after row=bottomrule},
%every other row/.style = {multicolumn{4}{l}{...}}
]{data.csv}
end{document}
pgfplotstable multicolumn
add a comment |
up vote
0
down vote
favorite
I am trying to make a table using pgfplotstable
, and am having difficulties because the csv
's are jagged. Most rows have 4 columns, as do the headers, but some rows are only 1 column and I would like these 1-cell rows to span the width of the table.
How do I either have pgfplotstable
dynamically create multicolumns depending on the csv, or set every other row to be a multicolumn using data from the csv?
mwe (does not produce the proper layout):
documentclass{article}
usepackage{pgfplotstable,multirow,booktabs}
begin{filecontents}{data.csv}
ColumnHeader1, ColumnHeader2, ColumnHeader3, ColumnHeader4
item1, string1, string2, string3
some-text-goes-here
item2, string1, string2, string3
some-more-text-goes-here
end{filecontents}
begin{document}
pgfplotstabletypeset[
col sep = comma,
column type = l,
string type,
multicolumn names,
every head row/.style={before row=toprule, after row=midrule},
every last row/.style={after row=bottomrule},
%every other row/.style = {multicolumn{4}{l}{...}}
]{data.csv}
end{document}
pgfplotstable multicolumn
1
Welcome to TeX.SX! Please add a minimal working example (MWE), not not just a fragment. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass and ending with end{document}
– albert
Aug 27 at 17:51
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to make a table using pgfplotstable
, and am having difficulties because the csv
's are jagged. Most rows have 4 columns, as do the headers, but some rows are only 1 column and I would like these 1-cell rows to span the width of the table.
How do I either have pgfplotstable
dynamically create multicolumns depending on the csv, or set every other row to be a multicolumn using data from the csv?
mwe (does not produce the proper layout):
documentclass{article}
usepackage{pgfplotstable,multirow,booktabs}
begin{filecontents}{data.csv}
ColumnHeader1, ColumnHeader2, ColumnHeader3, ColumnHeader4
item1, string1, string2, string3
some-text-goes-here
item2, string1, string2, string3
some-more-text-goes-here
end{filecontents}
begin{document}
pgfplotstabletypeset[
col sep = comma,
column type = l,
string type,
multicolumn names,
every head row/.style={before row=toprule, after row=midrule},
every last row/.style={after row=bottomrule},
%every other row/.style = {multicolumn{4}{l}{...}}
]{data.csv}
end{document}
pgfplotstable multicolumn
I am trying to make a table using pgfplotstable
, and am having difficulties because the csv
's are jagged. Most rows have 4 columns, as do the headers, but some rows are only 1 column and I would like these 1-cell rows to span the width of the table.
How do I either have pgfplotstable
dynamically create multicolumns depending on the csv, or set every other row to be a multicolumn using data from the csv?
mwe (does not produce the proper layout):
documentclass{article}
usepackage{pgfplotstable,multirow,booktabs}
begin{filecontents}{data.csv}
ColumnHeader1, ColumnHeader2, ColumnHeader3, ColumnHeader4
item1, string1, string2, string3
some-text-goes-here
item2, string1, string2, string3
some-more-text-goes-here
end{filecontents}
begin{document}
pgfplotstabletypeset[
col sep = comma,
column type = l,
string type,
multicolumn names,
every head row/.style={before row=toprule, after row=midrule},
every last row/.style={after row=bottomrule},
%every other row/.style = {multicolumn{4}{l}{...}}
]{data.csv}
end{document}
pgfplotstable multicolumn
pgfplotstable multicolumn
edited Aug 27 at 20:04
asked Aug 27 at 17:33
KeBr
12
12
1
Welcome to TeX.SX! Please add a minimal working example (MWE), not not just a fragment. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass and ending with end{document}
– albert
Aug 27 at 17:51
add a comment |
1
Welcome to TeX.SX! Please add a minimal working example (MWE), not not just a fragment. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass and ending with end{document}
– albert
Aug 27 at 17:51
1
1
Welcome to TeX.SX! Please add a minimal working example (MWE), not not just a fragment. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass and ending with end{document}
– albert
Aug 27 at 17:51
Welcome to TeX.SX! Please add a minimal working example (MWE), not not just a fragment. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass and ending with end{document}
– albert
Aug 27 at 17:51
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
If you want to have multicolumns by default, with the exception of the head row and possibly other exceptions, you can hack "typeset cell" from the columns.
The default is:
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
And you make it out of it:
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
MWE:
documentclass[margin=5pt,]{standalone}
%documentclass{article}
usepackage{pgfplotstable,booktabs, filecontents}
pgfplotsset{compat=1.12}
begin{filecontents*}{jobname-data.csv}
A,B,C,D
Some Text goes here in a multicolum., , ,
string1 (bad), string2, string3, string4
string1 (good), string2, string3, string4
Some more Text goes here in a multicolum., , ,
Some Text goes here in a multicolum., , ,
end{filecontents*}
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
begin{document}
pgfplotstabletypeset[col sep = comma,
string type,
column type = l,
multicolumn names,
every head row/.style={before row=toprule, after row=midrule},
every last row/.style={after row=bottomrule},
]{jobname-data.csv}
end{document}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If you want to have multicolumns by default, with the exception of the head row and possibly other exceptions, you can hack "typeset cell" from the columns.
The default is:
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
And you make it out of it:
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
MWE:
documentclass[margin=5pt,]{standalone}
%documentclass{article}
usepackage{pgfplotstable,booktabs, filecontents}
pgfplotsset{compat=1.12}
begin{filecontents*}{jobname-data.csv}
A,B,C,D
Some Text goes here in a multicolum., , ,
string1 (bad), string2, string3, string4
string1 (good), string2, string3, string4
Some more Text goes here in a multicolum., , ,
Some Text goes here in a multicolum., , ,
end{filecontents*}
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
begin{document}
pgfplotstabletypeset[col sep = comma,
string type,
column type = l,
multicolumn names,
every head row/.style={before row=toprule, after row=midrule},
every last row/.style={after row=bottomrule},
]{jobname-data.csv}
end{document}
add a comment |
up vote
0
down vote
If you want to have multicolumns by default, with the exception of the head row and possibly other exceptions, you can hack "typeset cell" from the columns.
The default is:
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
And you make it out of it:
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
MWE:
documentclass[margin=5pt,]{standalone}
%documentclass{article}
usepackage{pgfplotstable,booktabs, filecontents}
pgfplotsset{compat=1.12}
begin{filecontents*}{jobname-data.csv}
A,B,C,D
Some Text goes here in a multicolum., , ,
string1 (bad), string2, string3, string4
string1 (good), string2, string3, string4
Some more Text goes here in a multicolum., , ,
Some Text goes here in a multicolum., , ,
end{filecontents*}
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
begin{document}
pgfplotstabletypeset[col sep = comma,
string type,
column type = l,
multicolumn names,
every head row/.style={before row=toprule, after row=midrule},
every last row/.style={after row=bottomrule},
]{jobname-data.csv}
end{document}
add a comment |
up vote
0
down vote
up vote
0
down vote
If you want to have multicolumns by default, with the exception of the head row and possibly other exceptions, you can hack "typeset cell" from the columns.
The default is:
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
And you make it out of it:
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
MWE:
documentclass[margin=5pt,]{standalone}
%documentclass{article}
usepackage{pgfplotstable,booktabs, filecontents}
pgfplotsset{compat=1.12}
begin{filecontents*}{jobname-data.csv}
A,B,C,D
Some Text goes here in a multicolum., , ,
string1 (bad), string2, string3, string4
string1 (good), string2, string3, string4
Some more Text goes here in a multicolum., , ,
Some Text goes here in a multicolum., , ,
end{filecontents*}
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
begin{document}
pgfplotstabletypeset[col sep = comma,
string type,
column type = l,
multicolumn names,
every head row/.style={before row=toprule, after row=midrule},
every last row/.style={after row=bottomrule},
]{jobname-data.csv}
end{document}
If you want to have multicolumns by default, with the exception of the head row and possibly other exceptions, you can hack "typeset cell" from the columns.
The default is:
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
And you make it out of it:
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
MWE:
documentclass[margin=5pt,]{standalone}
%documentclass{article}
usepackage{pgfplotstable,booktabs, filecontents}
pgfplotsset{compat=1.12}
begin{filecontents*}{jobname-data.csv}
A,B,C,D
Some Text goes here in a multicolum., , ,
string1 (bad), string2, string3, string4
string1 (good), string2, string3, string4
Some more Text goes here in a multicolum., , ,
Some Text goes here in a multicolum., , ,
end{filecontents*}
pgfplotstableset{
typeset cell/.code={%%
ifnumpgfplotstablerow=-1% Head Row (Exception)
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else
ifnumpgfplotstablerow=2% Another Exception Row ...
ifnumpgfplotstablecol=pgfplotstablecols%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1\}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{#1 &}%
fi%
else%
ifnumpgfplotstablecol=pgfplotstablecols% Standard
pgfkeyssetvalue{/pgfplots/table/@cell content}{\}%
else%
ifnumpgfplotstablecol=1%
pgfkeyssetvalue{/pgfplots/table/@cell content}{multicolumn{4}{c}{#1}}%
else%
pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
fifififi%
},%%
}
begin{document}
pgfplotstabletypeset[col sep = comma,
string type,
column type = l,
multicolumn names,
every head row/.style={before row=toprule, after row=midrule},
every last row/.style={after row=bottomrule},
]{jobname-data.csv}
end{document}
answered Nov 13 at 20:56
cis
607514
607514
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f448037%2fpgfplotstable-have-every-other-row-be-a-multicolumn%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Welcome to TeX.SX! Please add a minimal working example (MWE), not not just a fragment. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with documentclass and ending with end{document}
– albert
Aug 27 at 17:51