我正在尝试转置一个表格,其中有一列是使用创建的,create on use
但是转置后的表格的第二行没有显示,垂直分隔条丢失,并且转置后的表格中的 $x$ 的数学模式被忽略。这是我的示例:
\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
x
1
2
3
4
5
6
7
8
}\mytable
\pgfplotstableset{
create on use/y/.style={
create col/expr={\thisrow{x}^2}
}
}
\pgfplotstabletranspose[string type,
colnames from=x,
input colnames to=x
]\mytablenew{\mytable}
Original table:
\begin{center}
\pgfplotstabletypeset[
columns={x,y},
columns/x/.style={column name=$x$},%
columns/y/.style={column name=$y$},%
]{\mytable}
\end{center}
\vspace*{1ex}
Transposed table:
\begin{center}
\pgfplotstabletypeset[
%rows={x,y}, %doesn't work
every head row/.style={
after row=\midrule
},
every column/.style={column type={l|}},
every last column/.style={column type={l}},
row/x/.style={row name=$x$},
row/y/.style={row name=$y$}
string type]{\mytablenew}
\end{center}
\end{document}
我怎样才能让它工作?
答案1
对于创建的 y 列,您可以使用
\pgfplotstablesave[columns={x,y}]{\mytable}{mytable1.dat}
并转置该表。添加的表的表头是转置表的第 0. 列,因此你必须说
display columns/0/.style={ column name=$x$, string type, postproc cell content/.style={@cell content={$##1$} },%<-- new }
全部一起:
\documentclass[margin=5pt, varwidth]{standalone}
%\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
x
1
2
3
4
5
6
7
8
}\mytable
Original Table:
\pgfplotstabletypeset[]{\mytable}
%
\pgfplotstableset{
create on use/y/.style={
create col/expr={\thisrow{x}^2}
}}
%
Added Table:
\pgfplotstabletypeset[
columns={x,y},
columns/x/.style={column name=$x$},
columns/y/.style={column name=$y$},
]{\mytable}
\pgfplotstablesave[columns={x,y}]{\mytable}{mytable1.dat}%<-- !
Saved Table:
\pgfplotstabletypeset[]{mytable1.dat}
%
\pgfplotstabletranspose[%columns={x,y},
colnames from=x,
input colnames to=x,
]\mytablenew{mytable1.dat}%<-- new, old: \mytable
\bigskip
Transposed Table:
% Suggestion:
\newcolumntype{L}{>{\raggedleft\arraybackslash}p{1.5em}|}
\pgfplotstabletypeset[%string type,%<-- new
every head row/.style={after row=\hline%<-- new, old: \midrule
},
% every column/.style={} % I do not found this command in the manual
every even column/.style={column type=L },
every odd column/.style={column type=L },
every last column/.style={column type=L },
display columns/0/.style={
column name=$x$,
string type,
postproc cell content/.style={@cell content={$##1$} },%<-- new
},
]{\mytablenew}
\end{document}