# pgfplotstable adding vertical space between fractions

MWE

% stand-alone file to test writing a table in pgfplotstable
\documentclass{book}
\usepackage{booktabs,multirow} % required
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}
\begin{document}
%\renewcommand{\arraystretch}{1.2}
\pgfplotstabletypeset
[
after row = \vspace{0.8mm},
{
before row = \toprule,
after row = \midrule,
},
every last row/.style =
{
after row = \bottomrule,
},
columns/x/.style =
{
column type = r,
column name = $x$,
frac,
},
columns/y/.style =
{
column type = r,
column name = ${y=\frac{2}{x}}$,
frac,
},
]
{
x    y
-4   -0.5         % vertical space not added after this row
-3   -0.66666666  % vert space added below here
-2   -1
-1   -2
-0.5 -4
0.5  4
1    2
2    1
3    0.66666666
4    0.5
} % \pgfplotstabletypeset{} END
\end{document}


To display columns of fractions (with pgfplotstable, booktabs and multirows), I need to add vertical space between the rows so the fraction of the current row does not step on the fraction of the previous row. As shown in the MWE, I added

after row = {\vspace{0.8mm}},


to the options for \pgfplotstabletypeset, but it compiled by adding space to every row after row 1, not between rows 0 and 1. See image.

I added the usual arraystretch command (commented out in MWE) prior to \pgfplotstabletypeset, but it is outside my block, and since I have dozens of tables in this document, not all need to have the array stretch applied. Yes, I could put braces around the source text, but I hope there is something cleaner to add to the options that I missed.

Why is the space not added between rows 0 and 1?

pgfplotstable allows you to specify the code for fractions via frac TeX. This can be used to add more vertical space where fractions appear e.g. by adding a vertical phantom.

\documentclass{book}
\usepackage{booktabs,multirow} % required
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}
\begin{document}
%\renewcommand{\arraystretch}{1.2}
\pgfplotstabletypeset
[
after row ={[0.3ex]}, %<use this instead of \vspace
frac TeX=\vphantom{\displaystyle\frac{1}{2}}\frac,
{
before row = \toprule,
after row = \midrule,
},
every last row/.style =
{
after row = \bottomrule,
},
columns/x/.style =
{
column type = r,
column name = $x$,
frac,
},
columns/y/.style =
{
column type = r,
column name = ${y=\frac{2}{x}}$,
frac,
},
]
{
x  y
-4 -0.5
-3 -0.66666666
-2 -1
-1 -2
-0.5   -4
0.5   4
1 2
2 1
3 0.66666666
4 0.5
} % \pgfplotstabletypeset{} END
\end{document}


• Is it possible to add \hline to each line? Apr 3 '19 at 5:18
• @manooooh Yes, e.g. with after row ={[0.3ex] \midrule},.
– user121799
Apr 3 '19 at 5:21