siunitxlink to pdf का उपयोग कर एक उदाहरण। प्रस्तावना में आप अपने डिफ़ॉल्ट विकल्पों को परिभाषित कर सकते हैं जिन्हें आप दस्तावेज़ में बाद में ओवरराइड कर सकते हैं।
संख्यात्मक उत्पादन के लिए:
num <- function(x,round_precision=NULL)
{
if (is.null(round_precision)) {
return(sprintf("\\num{%s}", x))
} else {
return(sprintf("\\num[round-precision=%s]{%s}",round_precision, x))
}
}
वैज्ञानिक उत्पादन के लिए:
sci<- function(x,round_precision=NULL){
if (is.null(round_precision)) {
return(sprintf("\\num[scientific-notation = true]{%s}", x))
} else {
return(sprintf("\\num[round-precision=%s,scientific-notation = true]{%s}",round_precision, x))
}
}
यहाँ एक पूर्ण प्रतिलिपि प्रस्तुत करने योग्य .Rnw स्क्रिप्ट है (साथ knitr प्रयोग की जाने वाली ... के लिए दोबारा के बजाय फ़ंक्शन में चार एंटीस्लाश का उपयोग करें SO post देखें।)
\documentclass[a4paper]{article}
\usepackage{siunitx}
%\usepackage{Sweave}
\title{siunitx}
\sisetup{
round-mode = figures,
round-precision = 3,
group-separator = \text{~}
}
\begin{document}
\maketitle
<<sanitize_number,echo=FALSE>>=
num <- function(x,round_precision=NULL)
{
if (is.null(round_precision)) {
return(sprintf("\\num{%s}", x))
} else {
return(sprintf("\\num[round-precision=%s]{%s}",round_precision, x))
}
}
sci<- function(x,round_precision=NULL){
if (is.null(round_precision)) {
return(sprintf("\\num[scientific-notation = true]{%s}", x))
} else {
return(sprintf("\\num[round-precision=%s,scientific-notation = true]{%s}",round_precision, x))
}
}
@
Examples :\\
$num$ for number formatting :
\begin{itemize}
\item \textbf{num(pi, round\_precision=2)} $\Rightarrow$
\num[round-precision=2]{3.14159265358979}
\item \textbf{num(pi, round\_precision=4)} $\Rightarrow$
\num[round-precision=4]{3.14159265358979}
\item The default formatting (here round-precision=3) is taken from
\textbf{\textbackslash sisetup}
\textbf{num(pi)} $\Rightarrow$ \num{3.14159265358979}\\
\end{itemize}
\noindent $sci$ for scientific notation :
\begin{itemize}
\item \textbf{sci(12.5687e4)} $\Rightarrow$ \num[scientific-notation =
true]{125687}
\item \textbf{sci(125687.11111)} $\Rightarrow$
\num[scientific-notation = true]{125687.11111}
\item \textbf{sci(125687.11111, round\_precision=4)} $\Rightarrow$
\Sexpr{sci(125687.11111, round_precision=4)}
\end{itemize}
\end{document}
दमिट, मुझे तैयार उत्तर के साथ मुझे हराया। :) –
समारोह को बदलने के लिए 0 और नकारात्मक मामलों को भी शामिल किया गया। –
@ सच्चा।दिलचस्प और उपयोगी। बहुत बहुत धन्यवाद और 1 वोट। – yCalleecharan