The easiest solution may be to put the pgfplotstable
into the \resizebox
command.
From Wikibooks:
The graphicx
packages features the command \resizebox{width}{height}{object}
which can be used with tabular
to specify the height and width of a table.
\documentclass{standalone}
\listfiles
\usepackage{colortbl}
\usepackage{array}
\usepackage{filecontents}
\usepackage{pgfplotstable}
\usepackage{graphicx}
\usetikzlibrary{pgfplots.colormaps}
\pgfplotsset{compat=1.9}
\pgfplotsset{
colormap={myCustomColorMap}{
color(0)=(blue);
color(1)=(red);
},
}
% http://tex.stackexchange.com/a/158985/31877
\pgfplotstableset{
/color cells/min/.initial=0,
/color cells/max/.initial=1000,
/color cells/textcolor/.initial=,
/color cells/colormap name/.initial=,% this was added
%
% Usage: 'color cells={min=<value which is mapped to lowest color>,
% max = <value which is mapped to largest>}
color cells/.code={%
\pgfqkeys{/color cells}{#1}%
\pgfkeysalso{%
postproc cell content/.code={%
\begingroup
% acquire the value before any number printer changed it:
\pgfkeysgetvalue{/pgfplots/table/@preprocessed cell content}\value
\ifx\value\empty
\endgroup
\else
\pgfkeys{/pgf/fpu=true}%
\pgfmathparse{log10(\value)}%
\pgfmathfloattofixed{\pgfmathresult}%
\let\value=\pgfmathresult
\pgfkeys{/pgf/fpu=false}%
% map that value:
\pgfplotscolormapaccess
[\pgfkeysvalueof{/color cells/min}:\pgfkeysvalueof{/color cells/max}]
{\value}
{\pgfkeysvalueof{/color cells/colormap name}}% I CHANGED THIS
% now, \pgfmathresult contains {<R>,<G>,<B>}
%
% acquire the value AFTER any preprocessor or
% typesetter (like number printer) worked on it:
\pgfkeysgetvalue{/pgfplots/table/@cell content}\typesetvalue
\pgfkeysgetvalue{/color cells/textcolor}\textcolorvalue
% tex-expansion control
\toks0=\expandafter{\empty}%\typesetvalue}%
\xdef\temp{%
\noexpand\pgfkeysalso{%
@cell content={%
\noexpand\cellcolor[rgb]{\pgfmathresult}%
\noexpand\definecolor{mapped color}{rgb}{\pgfmathresult}%
\ifx\textcolorvalue\empty
\else
\noexpand\color{\textcolorvalue}%
\fi
\the\toks0 %
}%
}%
}%
\endgroup
\temp
\fi
}%
}%
}
}
\pgfmathdeclarefunction{lg10}{1}{%
\pgfmathparse{ln(#1)/ln(10)}%
}
\begin{filecontents}{data.csv}
item,Xa,Xb,Ya,Yb,Za,Zb
a,2,,2,,783764,783764
b,,2,,,500000,500000
c,,5,,,100000,100000
d,2,,8,,20000,20000
e,,,,,10000,10000
f,,,,3,5000,5000
g,,2,,,1000,1000
h,6,,,4,500,500
i,,,4,,100,100
j,,,,,50,50
k,,2,,,10,10
l,,,7,,5,5
m,,6,,3,2,2
n,,,,,1,1
\end{filecontents}
\newcolumntype{C}{>{\centering\arraybackslash}p{1mm}}
\begin{document}
\resizebox{3in}{2in}{\pgfplotstabletypeset[
font=\tiny,
every head row/.style={
typeset cell/.code={
\ifnum\pgfplotstablecol=1
\pgfkeyssetvalue{/pgfplots/table/@cell content}{&}%
\else
\ifnum\pgfplotstablecol=\pgfplotstablecols
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\rotatebox{90}{##1}\\}%
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\rotatebox{90}{##1}&}%
\fi
\fi
}
},
%max=lg10(783764)
colorCell/.style={
column type=C,
color cells={min=0,max=5.9,colormap name=myCustomColorMap}
},
itemCell/.style={
string type,
column name={},
},
col sep=comma,
columns={item,Xa,Xb,Ya,Yb,Za,Zb},
columns/item/.style={itemCell},
columns/Xa/.style={colorCell},
columns/Xb/.style={colorCell},
columns/Ya/.style={colorCell},
columns/Yb/.style={colorCell},
columns/Za/.style={colorCell},
columns/Zb/.style={colorCell},
]{data.csv}}
\end{document}
One strange thing about this though is that even though I specify the options width=3in
and height=2in
to \resizebox
, for some reason my output has width 3.01 in and height 3.9 in.
I don't know why \resizebox
gets the height wrong by a multiplicative factor.
I just ran into the same issue. (It's really annoying when trying to produce print-quality preprint versions of the paper.) Poking around in pnastwo.cls, I found the following fix:
Find the first line in pnastwo.cls which says
\ifx\@captype\xtable
Change this to
\ifx\@captype\table
Alternatively, if you don't want to touch the class file, you can
put the following into the preamble of your document:
% Fix wierd behavior which prevents table captions from appearing for
% tables in the body of the article
\makeatletter
\long\def\@makecaption#1#2{%
\ifx\@captype\table
\let\currtabcaption\relax
\gdef\currtabcaption{
\tabnumfont\relax #1. \tabtextfont\relax#2\par
\vskip\belowcaptionskip
}
\else
\vskip\abovecaptionskip
\sbox\@tempboxa{\fignumfont#1.\figtextfont\hskip.5em\relax #2}%
\ifdim \wd\@tempboxa >\hsize
\fignumfont\relax #1.\figtextfont\hskip.5em\relax#2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\fi
}
\makeatother
One additional comment: once this bug is fixed, you'll almost certainly run into another issue which you'd want fixed if you use the PNAS two-column class to produce production-quality output: Unless you define floats with the h "here" placement, it loses the labels, so all cross-referencing of figures and tables breaks. Here is the fix, for direct pasting into the document preamble. You can also patch up the macro \DonormalEndcol pnastwo.cls, it's the same mistake 6 times over...
% And another fix. PNAS class loses the label of floats unless they
% were defined with the [h] option (so not really floats at all). It
% all comes down to wrong scope in the following routine which pushes
% out the floats onto the page. This is the fixed version:
\makeatletter
\def\DonormalEndcol{%
%% top float ==>
\ifx\toporbotfloat\xtopfloat%
%% figure ==>
\ifcaptypefig%
\expandafter\gdef\csname topfloat\the\figandtabnumber\endcsname{%
\vbox{\vskip\PushOneColTopFig%
\unvbox\csname figandtabbox\the\loopnum\endcsname%
\vskip\abovefigcaptionskip%
\csname caption\the\loopnum\endcsname%
\csname letteredcaption\the\loopnum\endcsname%
\csname continuedcaption\the\loopnum\endcsname%
\csname letteredcontcaption\the\loopnum\endcsname
\ifredefining%
\csname label\the\loopnum\endcsname%
\expandafter\gdef\csname topfloat\the\loopnum\endcsname{}\fi}%
\vskip\intextfloatskip%%
\vskip-4pt %% probably an artifact of topskip??
}%
\else%
%% plate ==>
\ifcaptypeplate%
\expandafter\gdef\csname topfloat\the\figandtabnumber\endcsname{%
\vbox{\vskip\PushOneColTopFig%
\unvbox\csname figandtabbox\the\loopnum\endcsname
\vskip\abovefigcaptionskip
\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname
\csname continuedcaption\the\loopnum\endcsname
\csname letteredcontcaption\the\loopnum\endcsname
\ifredefining
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname topfloat\the\loopnum\endcsname{}\fi}
\vskip\intextfloatskip %%
\vskip-4pt %% probably an artifact of topskip??
}%
\else% table ==>
\expandafter\gdef\csname topfloat\the\figandtabnumber\endcsname{%
\vbox{\vskip\PushOneColTopTab %%
\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname
\csname continuedcaption\the\loopnum\endcsname
\csname letteredcontcaption\the\loopnum\endcsname
\vskip\captionskip
\unvbox\csname figandtabbox\the\loopnum\endcsname
\ifredefining
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname topfloat\the\loopnum\endcsname{}\fi
}\vskip\intextfloatskip %% why don't we need this?
\vskip-10pt}
\fi\fi%
%
\else% bottom float
%
\ifcaptypefig
\expandafter\gdef\csname botfloat\the\figandtabnumber\endcsname{%
\vskip\intextfloatskip
\vbox{\unvbox\csname figandtabbox\the\loopnum\endcsname
\vskip\abovefigcaptionskip
\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname%
\csname continuedcaption\the\loopnum\endcsname%
\csname letteredcontcaption\the\loopnum\endcsname%
\vskip\PushOneColBotFig%%
\ifredefining%
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname botfloat\the\loopnum\endcsname{}\fi}}%
\else
\ifcaptypeplate
\expandafter\gdef\csname botfloat\the\figandtabnumber\endcsname{%
\vskip\intextfloatskip
\vbox{\unvbox\csname figandtabbox\the\loopnum\endcsname
\vskip\abovefigcaptionskip
\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname%
\csname continuedcaption\the\loopnum\endcsname%
\csname letteredcontcaption\the\loopnum\endcsname%
\vskip\PushOneColBotFig%%
\ifredefining%
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname botfloat\the\loopnum\endcsname{}\fi}}%
\else% TABLE
\expandafter\gdef\csname botfloat\the\figandtabnumber\endcsname{%
\vskip\intextfloatskip
\vbox{\csname caption\the\loopnum\endcsname
\csname letteredcaption\the\loopnum\endcsname
\csname continuedcaption\the\loopnum\endcsname
\csname letteredcontcaption\the\loopnum\endcsname%
\vskip.5\intextfloatskip
\unvbox\csname figandtabbox\the\loopnum\endcsname%
\vskip\PushOneColBotTab
\ifredefining%
\csname label\the\loopnum\endcsname
\expandafter\gdef\csname botfloat\the\loopnum\endcsname{}\fi}}%
\fi\fi\fi}
\makeatother
Best Answer
Just let the
graphicx
package have its way: