2

Lets say I have the following LaTex number table:

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{lll}
0,209966415285772 & 0,107300702188478 & 0,220336484787743 \\
0,235535794083825 & 0,124200085401020 & 0,241022336291680 \\
0,238895516728854 & 0,112685447109388 & 0,241352008484367
\end{tabular}
\end{table}

How can I round e.g. rows 1-2 to 3 decimals and row 3 to 2 decimals?

The reason why I'm asking this is because I have a big table with a lot of numbers and I need to round different parts of the table differently. How can I do this? MWE?

  • Do you know the siunitx package? You could use that. – TeXnician Aug 9 '17 at 12:51
  • Thank you @TeXnician for your help! If it's not a big trouble for you could you give an example how it's done? :) – jjepsuomi Aug 9 '17 at 12:54
  • 1
    @jjepsuomi I'm not sure whether this is the way to go. Big tables with lots of numbers don't appear from nowhere. Probably it is much easier to process the table outside of a *.tex file with e.g. LibreOffice Calc and provide a table with the proper rounding. Use this table as input for your *.tex file. – Keks Dose Aug 9 '17 at 13:02
  • @KeksDose Thank you for your answer. I'll keep that in mind :) – jjepsuomi Aug 9 '17 at 13:03
4

a small variation of TEXnician answer (considering your comment):

\documentclass{article}
\usepackage{siunitx}

\begin{document}
\begin{table}
\sisetup{table-column-width=16ex,    % local setting for all S columns
         round-mode=places,round-precision=3}
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{SSS}
0,209 966 415 285 772 & 0,107300702188478 & 0,220336484787743 \\
0,235535794083825 & 0,124200085401020 & 0,241022336291680 \\
\end{tabular}\\
\sisetup{round-precision=2}          % change setting for next S columns
\begin{tabular}{SSS}
0,238895516728854 & 0,112685447109388 & 0,241352008484367
\end{tabular}
\end{table}
\end{document}

enter image description here

|improve this answer|||||
  • Excellent! That's it :) Thank you very much! – jjepsuomi Aug 9 '17 at 13:35
4

You can use siunitx. Note: for the last row you have to fake some horizontal space.

rounding

\documentclass{article}

\usepackage[input-decimal-markers={,},round-mode=places,round-precision=3]{siunitx}

\begin{document}
\begin{table}
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{SSS}
0,209966415285772 & 0,107300702188478 & 0,220336484787743 \\
0,235535794083825 & 0,124200085401020 & 0,241022336291680 \\
\sisetup{round-precision=2}\hphantom{-\,}\num{0,238895516728854} & 
  \sisetup{round-precision=2}\hphantom{-\,}\num{0,112685447109388} &
  \sisetup{round-precision=2}\hphantom{-\,}\num{0,241352008484367}
\end{tabular}
\end{table}
\end{document}

Update: I just had a discussion with the author of siunitx (Joseph Wright) and the setup macro is local (hence you can't change it for the following rows). Tables should be formatted column-wise eitherway. If you really need to alter that behavior, you can use an own command for that.

|improve this answer|||||
  • Thank you! =) It seems you round the last row number by number. What if you need to round the next 100 rows in a different way than the first 100 rows? – jjepsuomi Aug 9 '17 at 13:01
  • @jjepsuomi You can create an own macro like \newcommand\mytnum[1]{\sisetup{round-precision=2}\hphantom{-\,}\num{#1}} and use \mytnum{yournumberhere}. – TeXnician Aug 9 '17 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.