Numprint 小数部分不分隔

Numprint 小数部分不分隔

我知道这个问题有一个答案,siunitx但我想知道一个可能的解决方案numprint。我希望在小数点分隔符之前有三位数字分隔符,但在小数点分隔符之后没有。这是一个 MWE:

\documentclass{article}
\usepackage[french,english]{babel}
\usepackage[autolanguage]{numprint}

\begin{document}
Raw:
1234567.78907

Numprint English:
\numprint{1234567.78907}

\selectlanguage{french}
Numprint French:
\numprint{1234567.78907}

\selectlanguage{english}
Desired output in English:
1,234,567.78907

\selectlanguage{french}
Desired output in French:
1\,234\,567{,}78907
\end{document} 

在此处输入图片描述

答案1

该命令\npthousandthpartsep{separator}允许抑制法语和英语分隔符。

A

\documentclass{article}
\usepackage[french,english]{babel}
\usepackage[autolanguage]{numprint}

\begin{document}
    Raw:
    1234567.78907

    \npthousandthpartsep{}% added <<<<<<<<<<<<<
    Numprint English:
    \numprint{1234567.78907}
    
    \selectlanguage{french}
    \npthousandthpartsep{}% added <<<<<<<<<<<<<
    Numprint French:
    \numprint{1234567.78907}\bigskip
    
    \selectlanguage{english}
    Desired output in English:
    1,234,567.78907
    
    \selectlanguage{french}
    Desired output in French:
    1\,234\,567{,}78907
\end{document}

可以通过添加以下方法改变全局样式

\renewcommand{\npstyle<language>}{\npthousandthpartsep{}}

\documentclass{article}
\usepackage[french,english]{babel}
\usepackage[autolanguage]{numprint}

\renewcommand{\npstyleenglish}{%
     \npthousandsep{,}%
    \npthousandthpartsep{}}% added <<<

\begin{document}
    \renewcommand{\npstylefrench}{\npthousandthpartsep{}}   % added <<< 
    
    Raw:
    1234567.78907
    
    Numprint English:
    \numprint{1234567.78907}
    
    \selectlanguage{french}
    Numprint French:
    \numprint{1234567.78907}\bigskip
    
    \selectlanguage{english}
    Desired output in English:
    1,234,567.78907
    
    \selectlanguage{french}
    Desired output in French:
    1\,234\,567{,}78907
\end{document} 

该宏 \g@addto@macro 可用于将命令附加到现有\npstyle<language>命令。

\documentclass{article}
\usepackage[french,english]{babel}
\usepackage[autolanguage]{numprint}

\makeatletter
\g@addto@macro\npstyleenglish{%
    \npthousandthpartsep{}% added to english style<<<<
}%
\makeatother


\begin{document}
\makeatletter
\g@addto@macro\npstylefrench{%
    \npthousandthpartsep{}% added to french style <<<<
}%
\makeatother

    
    Raw:
    1234567.78907
    
    Numprint English:
    \numprint{1234567.78907}
    
    \selectlanguage{french}
    Numprint French:
    \numprint{1234567.78907}\bigskip
    
    \selectlanguage{english}
    Desired output in English:
    1,234,567.78907
    
    \selectlanguage{french}
    Desired output in French:
    1\,234\,567{,}78907
\end{document} 

相关内容