# Hline length not filling width of the table

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:

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.

I still have centering the text issue :/

• Could you please add a compilable MWE? – sporc Aug 15 at 9:37
• 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 Aug 15 at 9:41
• @sporc updated the code – Saravanabalagi Ramachandran Aug 15 at 9:43
• @egreg gotcha, thanks :) – Saravanabalagi Ramachandran Aug 15 at 9:51
• If you want the text to be centered just change r to c: \begin{tabular}{cS[table-format=8.2]} – sporc Aug 15 at 10:13

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:

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:

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}

• Why using 8.6? 2.6 should be enough. You get a lot of unnecessary white space – sporc Aug 15 at 9:58
• @sporc In a heat wave, Tom likes white space resembling an area covered with snow. ;-) – Przemysław Scherwentke Aug 15 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 Aug 15 at 10:09

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}