4

I have a table

Rank ITML  SDALF KISSME LDM   LMNN 
1    5.53  5.60  14.17  13.51 7.29 
5    18.89 23.45 48.54  40.73 21.00
10   29.96 36.09 52.57  52.13 32.06
20   44.20 51.96 70.53  70.81 48.94

The result I want is like

enter image description here

Concretely, I need to

  • Change row name to add citation
  • Make a row in bold style
  • Add \midrule behind a row in a specific name

In pgfplotstable, columns can be easily refered using their names. But I cannot find a solution to customize the row style as easy as column. Few solutions I can use pgfplotstabletranspose to make the table row-wise, but the first column is not treated as name, but a column of data in string type, which result in the following picture:

enter image description here

And in this way the row can only be refered to in number. I may change one row name like this:

\pgfplotstabletranspose[string type, colnames from=Rank, input colnames to=Rank]\loadedtable{cuhk03-sota.txt}
\pgfplotstabletypeset[
   string type,
   every head row/.style={before row=\toprule, after row=\midrule},
   every last row/.style={after row=\hline},
   every row 0 column Rank/.style={/pgfplots/table/@cell content/.add={\relax}{\cite{davis2007information}},},
}{\loadedtable}

But this is obviously not a neat way. When I add a row in the middle, all the row numbers below have to be changed! Is there a good way to deal with row names?

  • Adding the citation is the tricky bit. You might be better off using a tabular and \pgfplotstablegetelem. – John Kormylo Nov 13 '16 at 18:07
  • @JohnKormylo "Adding the citation is the tricky bit." I don't know why :) – cis Oct 27 '18 at 4:07
1

I don't agree with @JohnKormylo ;) The problem is not the citation, the problem is to

· Hack the head row for adding the word 'Rank' in some columns:

every head row/.style={
typeset cell/.code={%% add the word 'Rank'...
\ifnum\pgfplotstablecol=\pgfplotstablecols%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{Rank ##1\\}%
\else%
\ifnum\pgfplotstablecol=1%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{##1 &}%
\else%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{Rank ##1 &}%
\fi\fi%
}%%
},

· The citation, on the other hand, can simply be added by using biblatex/biber,
where we have to use a matching bibliography, and then

display columns/0/.style={
postproc cell content/.style={@cell content={##1 \cite{##1} }}
},

(or maybe another 'citation source' too; depending on where the labels come from).

· Alltogether:

enter image description here

% arara: pdflatex
% arara: biber
% arara: pdflatex
% arara: pdflatex

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{ITML,
title     = {Citation of ITML},  
}
@book{SDALF,
title     = {Citation of SDALF},  
}
@book{KISSME,
title     = {Citation of KISSME},  
}
@book{LDM,
title     = {Citation of LDM},  
}
@book{LMNN,
title     = {Citation of LMNN},  
}
\end{filecontents}

\documentclass[border=5pt, varwidth]{standalone}
\usepackage{pgfplotstable}

\usepackage[style=numeric]{biblatex} 
\addbibresource{\jobname.bib}
\usepackage[colorlinks=true, citecolor=purple, pdfborder={0 0 0}]{hyperref}

\begin{document}
\pgfplotstableread[header=true]{
Rank ITML  SDALF KISSME LDM   LMNN 
1    5.53  5.60  14.17  13.51 7.29 
5    18.89 23.45 48.54  40.73 21.00
10   29.96 36.09 52.57  52.13 32.06
20   44.20 51.96 70.53  70.81 48.94
}\Actual

\textbf{\Large  Actual:} \pgfplotstabletypeset[string type]{\Actual} 
\bigskip

\pgfplotstableset{string type,
column type={>{\bfseries}c}, % bfseries for head row (1/2)
postproc cell content/.append style={% normalfont for cells (2/2)
/pgfplots/table/@cell content/.add={\fontseries{\seriesdefault}\selectfont}{}
},
%
every head row/.style={
before row=\hline, 
after row=\hline,
typeset cell/.code={%% add the word 'Rank'...
\ifnum\pgfplotstablecol=\pgfplotstablecols%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{Rank ##1\\}%
\else%
\ifnum\pgfplotstablecol=1%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{##1 &}%
\else%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{Rank ##1 &}%
\fi\fi%
}%%
},
%
every last row/.style={
after row=\hline,
},
%
display columns/0/.style={% citations
postproc cell content/.style={@cell content={##1 \cite{##1} }},
column type=l,
},
}

\textbf{\Large Target:} \pgfplotstabletranspose[
colnames from=Rank,
input colnames to=Method,
]\Target{\Actual}
\pgfplotstabletypeset[]{\Target}

%\cite{ITML} 
\printbibliography[title=Citations]
\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.