
Tenho uma tabela para orçamento, que utiliza 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}
Quero arredondar os preços para 2 casas decimais e as quantidades para nenhuma. Atualmente, esse código arredonda todos para 2 casas decimais. Como selecionar o número de casas decimais por coluna?
Responder1
Você pode usar, por exemplo, o pacote numprint
que oferece com o tipo de coluna N{6}{2}
a possibilidade de formatar os números na coluna, \nprounddigits{2}
podendo arredondar seus números conforme desejado.
Seu trecho de código alterado 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}
E você obtém o resultado:
Responder2
Eu sugiro o siunitx
pacote 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}