5

I used siunitx package to align numbers as suggested here.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}

\title{Test}
\date{August 2018}

\begin{document}

\maketitle

\section{Introduction}

\begin{tabular}{rS[table-format=8.2]}
\hline 
True sigma used & \ 9.117647 \\
True pixel value & 67.000000 \\
\hline
Pixel Value & 67.025372 \\
Error & \ 0.025372 \\
Squared Error & \ 0.000643 \\
Predicted Sigma & \ 8.787887 \\
Iteration Number & \text{87/100} \\
\hline
\end{tabular}

\end{document}

However, the \hlines do not go well with this I guess:

enter image description here

How do I fix this? Also, how do center align 87/100 or anything that's not a number?


Update : After @egreg 's comment, I noticed that changing table-format=8.2 to table-format=8.6 or table-format=x.6 (telling it to expect 6 digits after the decimal and x before it), hline alignment is gone :) Thanks.

enter image description here

I still have centering the text issue :/

4
  • Could you please add a compilable MWE?
    – sporc
    Commented Aug 15, 2018 at 9:37
  • 4
    Well, you're asking to reserve space for three digits in the integral part and two for the fractional part, but then use six for the latter.
    – egreg
    Commented Aug 15, 2018 at 9:41
  • @sporc updated the code Commented Aug 15, 2018 at 9:43
  • If you want the text to be centered just change r to c: \begin{tabular}{cS[table-format=8.2]}
    – sporc
    Commented Aug 15, 2018 at 10:13

2 Answers 2

5

You can center align the column by inserting a \multicolumn command.

Changing the format specifier to table-format=8.6 resolves the problem with the hline lenght:

Table with correct hline

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}

\title{Test}
\date{August 2018}

\begin{document}

\maketitle

\section{Introduction}

\begin{tabular}{rS[table-format=8.6]}
\hline 
True sigma used & 9.117647 \\
True pixel value & 67.000000 \\
\hline
Pixel Value & 67.025372 \\
Error & 0.025372 \\
Squared Error & 0.000643 \\
Predicted Sigma & 8.787887 \\
Iteration Number &  {87/100} \\
\hline
\end{tabular}

\end{document}

Better spacing

Changing the format specifier to table-format=2.6 removes unnecessary white space. Adding \renewcommand{\arraystretch}{1.3} adds some more spacing between the row of the table:

table with better spacing

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}

\begin{document}

% for spacing in the table
\renewcommand{\arraystretch}{1.3}

\begin{tabular}{rS[table-format=2.6]}
\hline 
True sigma used & 9.117647 \\
True pixel value & 67.000000 \\
\hline
Pixel Value & 67.025372 \\
Error & 0.025372 \\
Squared Error & 0.000643 \\
Predicted Sigma & 8.787887 \\
Iteration Number & {87/100} \\
\hline
\end{tabular}
\end{document}
3
  • Why using 8.6? 2.6 should be enough. You get a lot of unnecessary white space
    – sporc
    Commented Aug 15, 2018 at 9:58
  • @sporc In a heat wave, Tom likes white space resembling an area covered with snow. ;-) Commented Aug 15, 2018 at 10:04
  • I did not want to change more than neccessary. Sure, it may not look very nice. But then, I also think that the line spacing is not 'nice' and I didn't change it either. But I can change it.
    – Tom
    Commented Aug 15, 2018 at 10:09
4

With table-format=8.2 you reserve space for 8 digits before the dot and 2 after the dot, you need to change it to table-format=2.8, but for your given numbers 2.6 is enough

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}

\title{Test}
\date{August 2018}

\begin{document}

\maketitle

\section{Introduction}

\begin{tabular}{rS[table-format=2.6]}
\hline 
True sigma used & \ 9.117647 \\
True pixel value & 67.000000 \\
\hline
Pixel Value & 67.025372 \\
Error & \ 0.025372 \\
Squared Error & \ 0.000643 \\
Predicted Sigma & \ 8.787887 \\
Iteration Number & \text{87/100} \\
\hline
\end{tabular}

\end{document}

enter image description here

You must log in to answer this question.

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