1

Im experiencing problems using pgfplotstable. The following code does not produce exactly what I want:

\documentclass[a4paper,11pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{fontspec}
\setmainfont[Ligatures=TeX, Numbers={OldStyle,Proportional}]{Libertinus Serif}
\setsansfont[Numbers={OldStyle,Proportional}]{Libertinus Sans}
%\setmonofont{FreeMono}
\setmonofont[Scale=0.8]{DejaVu Sans Mono}
\usepackage{unicode-math}
\setmathfont{Libertinus Math}
\usepackage{polyglossia}
\setdefaultlanguage{catalan}
\usepackage{microtype}
\usepackage[svgnames]{xcolor}

\usepackage{siunitx}
\sisetup{
    output-decimal-marker = {,},
    per-mode = symbol,
    group-separator = {.},
    output-complex-root = \ensuremath{\mathrm{j}},
    binary-units,
    retain-unity-mantissa = false,
    retain-explicit-plus = true,
}

\usepackage{pgfplots}
\pgfplotsset{
  compat=1.11,
 /pgf/number format/use comma,
}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}

\usepackage{subcaption}
\captionsetup{font=sf}

\begin{document}

% NOTE: The data file contains:
% 0.01 13.649 88.982 20.373 22.89564181519858
% 0.02 13.649 150.51 76.303 50.69629924921932
% 0.04 13.649 361.35 239.26 66.21281306212813
% 0.08 13.929 816.86 433.06 53.01520456381754
% 0.16 14.81 1011.7 464.49 45.9118315706237
% 0.32 16.752 955.98 459.7 48.08678005816021
% 0.64 24.119 521.1400000000001 346.69 66.52530989753232

  \begin{table}[ht]
    \centering
    \caption{Resultats de les simulacions del Cas 2}\label{tbl:Cas2_resultats}
    \pgfplotstabletypeset[
      every head row/.style={before row=\toprule,after row=\midrule},
      every even row/.style={before row={\rowcolor[gray]{0.7}}},
      every last row/.style={after row=\bottomrule},
      every column/.style={fixed zerofill={1},precision=2},
      columns/0/.style={
        column name={Acoblament $k_{23}$},
        fixed,
      },
      columns/1/.style={
        column name={$f_\text{max}$ [\si{\mega\Hz}]},
      },
      columns/2/.style={
        column name={$P_g$ [\si{\milli\watt}]},
        dec sep align,
      },
      columns/3/.style={
        column name={$P_{_L}$ [\si{\milli\watt}]},
        dec sep align,
      },
      columns/4/.style={
        column name={$\eta_t$ [\si{\percent}]},
        dec sep align,
      },
    ]{Càlculs/Cas2_Taula.dat}
  \end{table}

\end{document}

The result is:

enter image description here

There are two problems:

  1. Although I've indicated "precision=2 and "fixed zerofill" options, some numbers are not filled with zeroes at decimal places. I would like read 76,30 and not 76,3.
  2. The fourth column (and perhaps the last too) of numbers is too displaced to the left, although the definition is the same as the previous one. I've tried the option "column type=c," to center the contents, but that completely destroys the layout.

Can anyone please help me with these two issues?

2
  • dec sep align separates the numbers into integer and decimal parts and puts them in separate columns to have alignment. Hence in its own point of view they are all integers. You need to preprocess them before the typesetting – percusse Dec 7 '16 at 13:08
  • I'll investigate this "preprocess" you are suggesting. By the way: the other problem (zero-filling) seems to be related to an erroneus option I was using: I put "fixed zerofill={1}" and it should be "fixed zerofill={true}" or simply "fixed zerofill". Sorry for the noise. – Orestes Mas Dec 7 '16 at 20:12
1

Partly resolved: The Zero fill problem was due to a bug in my code: I should have indicated "fixed zerofill={true}" ans NOT "fixed zerofill={1}".

The alignment problem requires further investigation, as Percusse suggested.

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.