Un bug di siuntix

  • Creatore
    Topic
  • #48084
    lorenzo.pantieri
    Partecipante
      Up
      0
      Down
      ::


      Ciao a tutti.

      Sono un estimatore del pacchetto siunitx: è la soluzione definitiva per la gestione dei dati numerici con LaTeX. Le colonne S, però, hanno un vero e proprio bug.
      `\documentclass{article}
      \usepackage{booktabs}
      \usepackage[mode=math,decimalsymbol=comma]{siunitx}

      \begin{document}

      \begin{tabular}{cSSSS}
      \toprule
      $D$ & {$P$} & {$u$} & {$\beta$} & {$G$} \\
      (m) & {(kg)} & {(m)} & & {(Pa)} \\
      \midrule
      $5$ & 269.8 & 0.000674 & 1.79 & 0.04089 \\
      $10$ & 421.0 & 0.001035 & 3.59 & 0.04089 \\
      $20$ & 640.2 & 0.001565 & 7.18 & 0.04089 \\
      \bottomrule
      \end{tabular}

      \begin{tabular}{c%
      S[tabformat=3.1]
      S[tabformat=1.6]
      S[tabformat=1.2]
      S[tabformat=1.5]}
      \toprule
      $D$ & {$P$} & {$u$} & {$\beta$} & {$G$} \\
      (m) & {(kg)} & {(m)} & & {(Pa)} \\
      \midrule
      $5$ & 269.8 & 0.000674 & 1.79 & 0.04089 \\
      $10$ & 421.0 & 0.001035 & 3.59 & 0.04089 \\
      $20$ & 640.2 & 0.001565 & 7.18 & 0.04089 \\
      \bottomrule
      \end{tabular}

      \end{document} `
      Come vedete, se non si specifica manualmente il formato di ciascuna colonna con la chiave tabformat, il risultato è inaccettabile.

      Enrico, in un altro topic, ha fatto presente come questo comportamento sia esclusivo di siunitx, che mette al centro di ogni colonna il separatore decimale, riservando uno spazio sempre uguale a sinistra e a destra del separatore (e riempiendolo, se necessario, di cifre “fantasma”).

      Questo problema non si presenta usando delle normalissime colonne c, che centrano il loro contenuto con un risultato perfetto (anche se, naturalmente, senza le funzioni di siunitx di resa dei numeri).

      `\documentclass{article}
      \usepackage{booktabs,amsmath}

      \begin{document}

      \[
      \begin{array}{ccccc}
      \toprule
      D & P & u & \beta & G \\
      \text{(m)} & \text{(kg)} & \text{(m)} & & \text{(Pa)} \\
      \midrule
      $5$ & 269.8 & 0.000674 & 1.79 & 0.04089 \\
      $10$ & 421.0 & 0.001035 & 3.59 & 0.04089 \\
      $20$ & 640.2 & 0.001565 & 7.18 & 0.04089 \\
      \bottomrule
      \end{array}
      \]

      \end{document}`
      Qualcuno avrebbe voglia di segnalare la cosa all’autore di siunitx?

      Mi piacerebbe che le colonne S fossero “più intelligenti”, e che dunque non ci fosse bisogno di usare tabformat come nell’esempio proposto.

      Grazie,
      L.

    Visualizzazione 0 filoni di risposte
    • Autore
      Risposte
      • #48085
        lorenzo.pantieri
        Partecipante
          Up
          0
          Down
          ::


          Cioa vi riporto la risposta di Joseph Wright:

          Hello Lorenzo,

          I have to start by saying that this is not a bug, it’s a deliberate
          design decision. I’ll explain the reasoning, but first I’ll point out
          that for cases such as your own you can use the ‘table-parse-only’
          option in siunitx version 2:
          `\documentclass{article}
          \usepackage{booktabs}
          \usepackage{siunitx}
          \sisetup{output-decimal-marker = {,},table-parse-only}
          \begin{document}

          \begin{tabular}{cSSSS}
          \toprule
          $D$& {$P$}& {$u$}& {$\beta$}& {$G$} \\
          (m)& {(kg)}& {(m)}& & {(Pa)} \\
          \midrule
          $5$& 269.8& 0.000674& 1.79& 0.04089 \\
          $10$& 421.0& 0.001035& 3.59& 0.04089 \\
          $20$& 640.2& 0.001565& 7.18& 0.04089 \\
          \bottomrule
          \end{tabular}

          \end{document}`

          (Version 2 of siunitx was released about two months ago.)

          The reason siunitx works in the way it does is because of the
          information you need in order to lay out numbers aligning on decimal
          markers. The default is to always put the marker at the middle of the
          column, and to allow each side to expand flexibly. That is relatively
          easy to do, as you only need a fill on both sides.

          However, life is much more complex when you want variable placement of
          the marker. In your examples, you’ve got ‘nice’ columns where each entry
          in a column has the same number of digits. For those, you can not worry
          about controlling the alignment, which is why the ‘c’ column type works.
          The ‘table-parse-only’ option does a very similar thing but with the
          digit formatting of siunitx.

          siunitx can’t make the assumption that each column is ‘well behaved’.
          There may be different numbers to print in each column, for example

          10.123
          4.56
          2.345

          So siunitx has to box things up to maintain alignment. That means that
          it needs to know how many digits to allow for, hence the need for the
          ‘table-format’ option (known as ‘tabformat’ in version 1 of siunitx).
          The way that tables are constructed by LaTeX means that this is not
          available at the start of a column, hence needing it from the user as an
          option. (I’ve thought about a two-pass automated system, but it’s a
          complicated issue.)

          Regards,

          Joseph

          Aspetto la Tex Live 2010 per probare l’opzione table-parse-only di siunitx 2.0.

          Ciao,
          L.

      Visualizzazione 0 filoni di risposte
      • Devi essere connesso per rispondere a questo topic.

      Go to top