我正在使用电子表格在 Latex 上开发一个简单的现金簿。我如何确保成本列始终给出精确到小数点后 2 位的值(它代表金钱)。我想要英国格式 xx.xx(而不是 xx,xx)。
如果可能的话,是否有可以在 Excel 上使用的等效会计格式,即左侧是 £ 符号,右侧是成本值?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{spreadtab}
\title{Spreadsheet}
\author{}
\date{}
\begin{document}
\begin{spreadtab}{{tabular}{c|c|c|c|c|c}}
@Date & @Date v.2 & @ Cost & @Fund & @Bank Acc & @Analysis \\
\hline
@01/01/2019 & 20190101 & 2.30 & @General & @HSBC &@Office Expenses \\
@02/01/2019 & 20190102 & 102.00 & @General & @HSBC &@ Rent\\
@02/01/2019 & 20190102 & 32.00 & @General & @HSBC &@ Hospitality\\
\hline
& & sum(c2:c4) && \\
\end{spreadtab}
\end{document}
答案1
借助siunitx
您可以实现以下目标:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{spreadtab}
\usepackage{siunitx}
\title{Spreadsheet}
\author{}
\date{}
\begin{document}
\begin{spreadtab}{{tabular}{c|c|S[table-format=3.2, round-integer-to-decimal, round-mode = places, round-precision = 2]|c|c|c}}
@Date & @Date v.2 & @ Cost & @Fund & @Bank Acc & @Analysis \\
\hline
@01/01/2019 & 20190101 & 2.30 & @General & @HSBC &@Office Expenses \\
@02/01/2019 & 20190102 & 102.00 & @General & @HSBC &@ Rent\\
@02/01/2019 & 20190102 & 32.00 & @General & @HSBC &@ Hospitality\\
\hline
& & sum(c2:c4) && \\
\end{spreadtab}
\bigskip
\begin{spreadtab}{{tabular}{c|c|S[table-format=3.2, round-integer-to-decimal, round-mode = places, round-precision = 2]|c|c|c}}
@Date & @Date v.2 & {@ Cost in \pounds} & @Fund & @Bank Acc & @Analysis \\
\hline
@01/01/2019 & 20190101 & 2.30 & @General & @HSBC &@Office Expenses \\
@02/01/2019 & 20190102 & 102.00 & @General & @HSBC &@ Rent\\
@02/01/2019 & 20190102 & 32.00 & @General & @HSBC &@ Hospitality\\
\hline
& & sum(c2:c4) && \\
\end{spreadtab}
\bigskip
\begin{spreadtab}{{tabular}{c|c|>{\pounds}S[table-format=3.2, round-integer-to-decimal, round-mode = places, round-precision = 2, table-space-text-pre=\pounds]|c|c|c}}
@Date & @Date v.2 & \multicolumn{1}{c|}{@ Cost} & @Fund & @Bank Acc & @Analysis \\
\hline
@01/01/2019 & 20190101 & 2.30 & @General & @HSBC &@Office Expenses \\
@02/01/2019 & 20190102 & 102.00 & @General & @HSBC &@ Rent\\
@02/01/2019 & 20190102 & 32.00 & @General & @HSBC &@ Hospitality\\
\hline
& & sum(c2:c4) && \\
\end{spreadtab}
\end{document}
答案2
由于spreadtab的作者似乎更喜欢使用numprint
,因此这里提供了一个N
列类型的解决方案。对于小数位数,您可以使用命令\STautoround*{2}
。对于£
货币单位,我建议一劳永逸地在列标题中使用它。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{makecell, numprint}
\usepackage{spreadtab}
\usepackage{numprint}
\npdecimalsign{.}
\title{Spreadsheet}
\author{}
\date{}
\begin{document}
\setlength{\extrarowheight}{2pt}
\STautoround*{2}
\begin{spreadtab}{{tabular}{c|c|N{3}{2}|c|c|c}}
@Date & @Date v.2 &\multicolumn{1}{c|}{\makecell{@ Cost\\ (£)}}& @Fund & @Bank Acc & @Analysis \\
\hline
@01/01/2019 & 20190101 & 2.301 & @General & @HSBC &@Office Expenses \\
@02/01/2019 & 20190102 & 102.997 & @General & @HSBC &@ Rent\\
@02/01/2019 & 20190102 & 31.998 & @General & @HSBC &@ Hospitality\\
\hline
& & sum(c2:c4) && \\
\end{spreadtab}
\end{document}