0

I have the following inline code to call a value from R code. The value called for example is 8000. I would like to format the value so there is a comma for the 1,000 place - for example 8,000.

The inline code is:

$\text{\Sexpr{table1.1[4,3]}}$

I am using R Studio and pdfLaTex.

1 Answer 1

1

You can use either the numprint package or the siunitx package in combination with \Sexpr. Using \text is not necessary. MWE:

\documentclass{article}
\usepackage{numprint}
\npthousandsep{,}
\usepackage{siunitx}
\sisetup{group-separator = {,}, group-minimum-digits = 4}
\begin{document}
<<echo=FALSE>>=
a <- 8000
@
$a_1=\numprint{\Sexpr{a}}$    % using numprint

$a_2=\num{\Sexpr{a}}$         % using siunitx
\end{document}

Result:

enter image description here

Of course when you use numprint you can delete the two lines about siunitx and vice versa. In general numprint is a bit easier to use but siunitx has (a lot) more features.

See also: Format long numbers with a thousand separator?, Preserving thousands separator with siunitx.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .