Variar el número de decimales en la pestaña de cálculo

Variar el número de decimales en la pestaña de cálculo

Tengo una tabla para un presupuesto, que usa spreadtab.

\STautoround*{2}
\begin{spreadtab}{{tabular}{lrrrr}}
@\textbf{Item}                  &@\textbf{Unit Value}&@\textbf{Unit Cost}&@\textbf{Quantity}&@\textbf{Total Price}\\
\hline
@7-segment display       &10        &1.00     &1050    &[-1,0] * [-2,0]\\
@Capacitor (100nF)       &0.08      &0.08     &1400    &[-1,0] * [-2,0]\\
@Capacitor (10$\mu$F)    &0.10      &0.10     &350     &[-1,0] * [-2,0]\\
\end{spreadtab}

Quiero redondear los precios a 2 decimales y las cantidades a ninguno. Actualmente, este código los redondea todos a 2 decimales. ¿Cómo se selecciona el número de decimales por columna?

Respuesta1

Puede usar, por ejemplo, el paquete numprintque le brinda, con el tipo de columna, N{6}{2}la posibilidad de formatear los números en la columna, con \nprounddigits{2}lo que puede redondear sus números como desee.

Su fragmento de código modificado como MWE:

\documentclass[ngerman]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}

\usepackage{spreadtab}
\usepackage{numprint}


\begin{document}

\STsetdecimalsep{,}  % German writing: comment it for english
\nprounddigits{2}

\begin{spreadtab}{{tabular}{lrrrN{6}{2}}}
@\textbf{Item}           &@\textbf{Unit Value}
                                    &@\textbf{Unit Cost}
                                              &@\textbf{Quantity}
                                                       &@\textbf{Total Price}\\
\hline
@7-segment display       &10        &1.13     &1050    &[-1,0] * [-2,0]\\
@Capacitor (100nF)       &0.08      &0.08     &1400    &[-1,0] * [-2,0]\\
@Capacitor (10$\mu$F)    &0.10      &0.10     &350     &[-1,0] * [-2,0]\\
\end{spreadtab}

\end{document}

Y obtienes el resultado:

ingrese la descripción de la imagen aquí

Respuesta2

Sugiero el siunitxpaquete poderoso.

\documentclass{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage{spreadtab}
\usepackage{siunitx}
\usepackage{booktabs}

\newcolumntype{E}[1]{% E for Euro; the argument is the number of digits in the mantissa
  S[table-format=#1.2,round-integer-to-decimal,round-mode=places,round-precision=2]%
}

\begin{document}

\begin{spreadtab}{%
  {tabular}{
    l
    S[table-format=2.2]
    E{1}
    S[table-format=4.0]
    S[table-format=4.2,round-mode=places,round-integer-to-decimal,round-precision=2]% customize at will
  }%
}
\toprule
@\textbf{Item}           &@\textbf{Unit Value}
                                    &@\textbf{Unit Cost}
                                              &@\textbf{Quantity}
                                                       &@\textbf{Total Price}\\
\midrule
@7-segment display       &10        &1.13     &1050    &[-1,0] * [-2,0]\\
@Capacitor (\SI{100}{\nano\farad})
                         &0.08      &0.08     &1400    &[-1,0] * [-2,0]\\
@Capacitor (\SI{10}{\micro\farad})
                         &0.10      &0.10     &350     &[-1,0] * [-2,0]\\
\bottomrule
\end{spreadtab}

\end{document}

ingrese la descripción de la imagen aquí

información relacionada