\num{100000}
打印 100 000
我想要 100,000。
问题:如何设置siunitx
包来执行上述操作?
多一点
\num{1000}
=> 1 000
\num{10000}
=> 10 000
\num{100000}
=> 1 00 000
\num{1000000}
=> 10 00 000
\documentclass[12pt]{article}
\usepackage{siunitx}
\sisetup{group-separator = {,}}
\begin{document}
\num{1000}
\num{10000}
\num{100000}
\num{1000000}
\num{10000000}
\num{100000000}
\num{1000000000}
\SI{1000000000}{m}
\end{document}
具体规则在维基百科条目:
印度数字系统使用的分隔符与阿拉伯系统不同;除了整数部分的三个最低有效数字外,逗号每两位而不是每三位数字进行分隔。
答案1
与此同时,在实际siunitx
解决方案出现之前,您可以使用这个可扩展宏。但它只适用于(长)整数。对于科学计数法中的数字,您需要某种东西来提取尾数,然后您可以\indianum
使用这个尾数进行输入。
\documentclass[12pt]{article}
%\usepackage{siunitx}
%\sisetup{group-separator = {,}}
\usepackage{xint}
\makeatletter
\newcommand\indianum[1]
{\expandafter\indianum@\romannumeral-`0#1!}
\def\indianum@ #1{\ifx #1-\expandafter\@firstoftwo
\else\expandafter\@secondoftwo\fi
{\expandafter-\romannumeral-`0\indianum@a}
{\indianum@a#1}}
\def\indianum@a #1!{\expandafter\indianum@b\expandafter
{\romannumeral-`0\xintLength{#1}}#1!}
\def\indianum@b #1{\xintifGt {#1}{3}
{\xintifOdd {#1}{\indianum@codd }
{\indianum@ceven }}
{\indianum@short}}
\def\indianum@short #1!{#1}
\def\indianum@codd #1#2#3#4{\indianum@loop {#1#2,}{#3#4}}
\def\indianum@ceven #1#2#3{\indianum@loop {#1,}{#2#3}}
\def\indianum@loop #1#2#3#4{\ifx #4!\expandafter\@firstoftwo
\else\expandafter\@secondoftwo\fi
{#1#2#3}{\indianum@loop {#1#2,}{#3#4}}}
\makeatother
\begin{document}
\indianum{1}
\indianum{10}
\indianum{100}
\indianum{1000}
\indianum{10000}
\indianum{100000}
\indianum{1000000}
\indianum{10000000}
\indianum{100000000}
\indianum{1000000000}
\indianum{-1}
\indianum{-10}
\indianum{-100}
\indianum{-1000}
\indianum{-10000}
\indianum{-100000}
\indianum{-1000000}
\indianum{-10000000}
\indianum{-100000000}
\indianum{-1000000000}
\end{document}
2017 年编辑(由评论转换而来)
可以只加载xintkernel
的非常小的子集xint
,包含其\xintLength
宏,并加载etoolbox
其整数比较条件来替换 的\xintifGt
和\xintifOdd
条件xint
,测试的数字当然足够短。
正如etoolbox
经常使用的那样,如果其他地方不需要的宏,这可能会很有用xint
(甚至可以简单地从etoolbox
包中复制它的定义\ifnumgreater
和\ifnumodd
它们是 TeX 原语的精简包装;那么只xintkernel
需要包。)
这是修改后的示例,产生相同的输出:
\documentclass[12pt]{article}
%\usepackage{siunitx}
%\sisetup{group-separator = {,}}
\usepackage{etoolbox}
\usepackage{xintkernel}
\makeatletter
\newcommand\indianum[1]{\expandafter\indianum@\romannumeral-`0#1!}
\def\indianum@ #1{\ifx #1-\expandafter\@firstoftwo
\else\expandafter\@secondoftwo\fi
{\expandafter-\romannumeral-`0\indianum@a}
{\indianum@a#1}}
\def\indianum@a #1!{\expandafter\indianum@b\expandafter
{\romannumeral-`0\xintLength{#1}}#1!}
\def\indianum@b #1{\ifnumgreater {#1}{3}
{\ifnumodd {#1}{\indianum@codd }
{\indianum@ceven }}
{\indianum@short}}
\def\indianum@short #1!{#1}
\def\indianum@codd #1#2#3#4{\indianum@loop {#1#2,}{#3#4}}
\def\indianum@ceven #1#2#3{\indianum@loop {#1,}{#2#3}}
\def\indianum@loop #1#2#3#4{\ifx #4!\expandafter\@firstoftwo
\else\expandafter\@secondoftwo\fi
{#1#2#3}{\indianum@loop {#1#2,}{#3#4}}}
\makeatother
\begin{document}
\indianum{1}
\indianum{10}
\indianum{100}
\indianum{1000}
\indianum{10000}
\indianum{100000}
\indianum{1000000}
\indianum{10000000}
\indianum{100000000}
\indianum{1000000000}
\indianum{-1}
\indianum{-10}
\indianum{-100}
\indianum{-1000}
\indianum{-10000}
\indianum{-100000}
\indianum{-1000000}
\indianum{-10000000}
\indianum{-100000000}
\indianum{-1000000000}
\end{document}