3

I am trying to transpose a table where one column was created using create on use however the second row of the transposed table doesn't show up, the vertical separation bars are missing and also the math mode is ignored for the $x$ in the transposed table. Here is my example:

\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}

enter image description here

How can I make this work?

  • you can't tranpose a table with a create on use because it is not on use at that time. You can save it as a new table and transpose that one instead of typesetting – percusse Oct 3 '16 at 16:58
0
  • For the created y-column you can work with
    \pgfplotstablesave[columns={x,y}]{\mytable}{mytable1.dat}
    and transpose this table.

  • The head of the added table is the 0. column of the transposed table, so you have to say
    display columns/0/.style={ column name=$x$, string type, postproc cell content/.style={@cell content={$##1$} },%<-- new }

Alltogether:

enter image description here

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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