4

I'm looking for a way to change row height or width with pgfplotstables. Even in the pgfplotstables manual I cant find anything about this matter.

I found a topic about this here but the only answer was using \resizebox. I dont like this since it changes proportions of the font used with the cells.

I'm looking for a solution because every lines is very close one to another, therefore the table becomes not easly readable.

4
  • Just realized by using \toprule, \midrule and \bottomrule instead of \hline for the row lines, I dont have the issues with the lines being very close one to another. But still if someone has a way to change column width and row height I'll be interested.
    – joseldsm
    Oct 12, 2018 at 12:09
  • The lines are also tight if no lines are used.
    – joseldsm
    Oct 12, 2018 at 12:51
  • 2
    The \arraystretch macro is used with tabular and array. See what \def\arraystretch{2} does to \pgfplotstabletypeset. You can also add struts (e.g. \rule{0pt}{1cm}). Oct 13, 2018 at 14:07
  • @JohnKormylo \def\arraystretch{2} does work for the row height. Thank you !
    – joseldsm
    Oct 15, 2018 at 7:38

2 Answers 2

2

Since there is no answer to this topic, I'll answer with what I came up with.

For the row height : The solution of @JohnKormylo works perfectly for what I need : \def\arraystretch{size}, "size" being the integer parameter.

For the column width : I use the same solution I used for the basics tabular and it works great :

\usepackage{array,multirow,makecell}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}
%[...]
columns/myColumnName/.style={column type=|C{1.4cm}|},

Hope it will help some beginners like me.

0

I was confused about this as well. The simplest way I can think of to do this is to use the \vphantom command within the table. Here are two tables -- one without the \vphantom and one with the \vphantom:

Without \vphantom

\begin{table}[htpb]
\centering
\pgfplotstabletypeset[
    col sep=&,
    row sep=\\,
    string type,
    columns = {x, N-x, pq, binom,prob},
    columns/x/.style={column name={\boldmath{$x$}\unboldmath},
                        column type={@{}M{.05\dimexpr\textwidth-6\tabcolsep}}} ,
    columns/N-x/.style={column name={\boldmath{$N-x$}\unboldmath},
                        column type={M{.1\dimexpr\textwidth-6\tabcolsep} }} ,
    columns/pq/.style={column name={\boldmath{$p^{x}\ q^{N - x}$}\unboldmath},
                        column type={M{.3\dimexpr\textwidth-6\tabcolsep} }} ,
    columns/binom/.style={column name={\boldmath{$\dfrac{N!}{x! (N - x)!}$}\unboldmath},
                        column type={M{.3\dimexpr\textwidth-6\tabcolsep}@{} }} ,
    columns/prob/.style={column name={\boldmath{$P(x)$}\unboldmath},
                        column type={M{.1\dimexpr\textwidth-6\tabcolsep}@{} }} ,   
    every head row/.style=
        {before row=\toprule\toprule, after row=\midrule},
    every last row/.style=
        {after row=\bottomrule\bottomrule},
    ]
    {
x & N-x & pq & binom & prob \\
{}3 & 0 & $\left(\dfrac{1}{2}\right)^3\left(\dfrac{1}{2}\right)^0 = \dfrac{1}{8}$ & $\dfrac{3!}{3! (0!)} = 1$ & $\dfrac{1}{8}$ \\
    \midrule
{}2 & 1 & $\left(\dfrac{1}{2}\right)^2\left(\dfrac{1}{2}\right)^1 = \dfrac{1}{8}$ & $\dfrac{3!}{2! (1!)} = 3$ & $\dfrac{3}{8}$ \\
    \midrule
{}1 & 2 & $\left(\dfrac{1}{2}\right)^1\left(\dfrac{1}{2}\right)^2 = \dfrac{1}{8}$ & $\dfrac{3!}{1! (2!)} = 3$ & $\dfrac{3}{8}$ \\
    \midrule
{}0 & 3 & $\left(\dfrac{1}{2}\right)^0\left(\dfrac{1}{2}\right)^3 = \dfrac{1}{8}$ & $\dfrac{3!}{0! (3!)} = 1$ & $\dfrac{1}{8}$ \\
    }
\caption{}
\end{table}

..and the above produces:

enter image description here

With \vphantom to add more space between the rows:

    \begin{table}[htpb]
\centering
\pgfplotstabletypeset[
    col sep=&,
    row sep=\\,
    string type,
    columns = {x, N-x, pq, binom,prob},
    columns/x/.style={column name={\boldmath{$x$}\unboldmath},
                        column type={@{}M{.05\dimexpr\textwidth-6\tabcolsep}}} ,
    columns/N-x/.style={column name={\boldmath{$N-x$}\unboldmath},
                        column type={M{.1\dimexpr\textwidth-6\tabcolsep} }} ,
    columns/pq/.style={column name={\boldmath{$p^{x}\ q^{N - x}$}\unboldmath},
                        column type={M{.3\dimexpr\textwidth-6\tabcolsep} }} ,
    columns/binom/.style={column name={\boldmath{$\dfrac{N!}{x! (N - x)!}$}\unboldmath},
                        column type={M{.3\dimexpr\textwidth-6\tabcolsep}@{} }} ,
    columns/prob/.style={column name={\boldmath{$P(x)$}\unboldmath},
                        column type={M{.1\dimexpr\textwidth-6\tabcolsep}@{} }} ,   
    every head row/.style=
        {before row=\toprule\toprule, after row=\midrule},
    every last row/.style=
        {after row=\bottomrule\bottomrule},
    ]
    {
x & N-x & pq & binom & prob \\
{}3 & 0 & $\Large \vphantom{\left(\dfrac{1}{2}\right)}$ $\left(\dfrac{1}{2}\right)^3\left(\dfrac{1}{2}\right)^0 = \dfrac{1}{8}$ & $\dfrac{3!}{3! (0!)} = 1$ & $\dfrac{1}{8}$ \\
    \midrule
{}2 & 1 & $\Large \vphantom{\left(\dfrac{1}{2}\right)}$ $\left(\dfrac{1}{2}\right)^2\left(\dfrac{1}{2}\right)^1 = \dfrac{1}{8}$ & $\dfrac{3!}{2! (1!)} = 3$ & $\dfrac{3}{8}$ \\
    \midrule
{}1 & 2 & $\Large \vphantom{\left(\dfrac{1}{2}\right)}$ $\left(\dfrac{1}{2}\right)^1\left(\dfrac{1}{2}\right)^2 = \dfrac{1}{8}$ & $\dfrac{3!}{1! (2!)} = 3$ & $\dfrac{3}{8}$ \\
    \midrule
{}0 & 3 & $\Large \vphantom{\left(\dfrac{1}{2}\right)}$ $\left(\dfrac{1}{2}\right)^0\left(\dfrac{1}{2}\right)^3 = \dfrac{1}{8}$ & $\dfrac{3!}{0! (3!)} = 1$ & $\dfrac{1}{8}$ \\
    }
\caption{}
\end{table}

and the above produces:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .