# hspace in tabular

How can I move the summation equation that appears at the bottom of column 3 to be centered with the column 3rd column. Using \hspace hasn't been successful thus far.

\begin{tabular}{ccr@{\hspace{1pt}=\hspace{1pt}}r}
$X_j$&$f_j$&\multicolumn{1}{r}{$f_jX_j$}\\

\hline

28&1&(1)(28)&28\\
27&0&(0)(27)&0\\
26&1&(1)(26)&26\\
25&2&(2)(25)&50\\
24&3&(3)(24)&72\\
23&4&(4)(23)&92\\
22&3&(3)(22)&66\\
21&0&(0)(21)&0\\
20&1&(1)(20)&20\\
19&2&(2)(19)&38\\
18&1&(1)(18)&18\\
17&0&(0)(17)&0\\
16&1&(1)(16)&16\\
15&0&(0)(15)&0\\
14&1&(1)(14)&14\\

\hline

&$n=20$& \multicolumn{1}{c}{$\displaystyle\sum^{k}_{j=1}f_jX_j=440$}

\end{tabular}


-
Using & $n=20$ & $\displaystyle\sum^{k}_{j=1}f_jX_j$ & 440 for the last row seems to be what you need? – Gonzalo Medina Aug 28 '12 at 21:20
That does work for this example. Thank you for the fresh eyes, I thought I had already done that. Is it possible to shift the alignment of the summation function independent of the =? I hoped there would be a way using \multicolumn – Daniel Aug 28 '12 at 21:26
OT: The $k$ above the summation should be changed to $n$. – Aditya Aug 28 '12 at 21:37

For proper spacing in your "equation" setup, you need to use something like @{${}={}$} (in order to make it a true relation). I've updated your tabular to use this, as well as inserting the total:

\documentclass{article}
\begin{document}
\begin{tabular}{ccr@{${}={}$}r}
$X_j$ & $f_j$ & \multicolumn{1}{c}{$f_jX_j$} \\
\hline
28 & 1 & (1)(28) & 28 \\
27 & 0 & (0)(27) &  0 \\
26 & 1 & (1)(26) & 26 \\
25 & 2 & (2)(25) & 50 \\
24 & 3 & (3)(24) & 72 \\
23 & 4 & (4)(23) & 92 \\
22 & 3 & (3)(22) & 66 \\
21 & 0 & (0)(21) &  0 \\
20 & 1 & (1)(20) & 20 \\
19 & 2 & (2)(19) & 38 \\
18 & 1 & (1)(18) & 18 \\
17 & 0 & (0)(17) &  0 \\
16 & 1 & (1)(16) & 16 \\
15 & 0 & (0)(15) &  0 \\
14 & 1 & (1)(14) & 14 \\
\hline
& $n=20$ & $\displaystyle\sum^{k}_{j=1}f_jX_j$ & $440$
\end{tabular}
\end{document}​

-
Can be improved by correting \multicolumn{1} to \multicolumn{2} in the first row. – Hans-Peter E. Kristiansen Aug 28 '12 at 21:35

You can add some padding before the third column and hide the width of the big summation:

\documentclass{beamer}
\usepackage{array}
\begin{document}
\begin{frame}
\begin{tabular}{cc@{\hspace{4em}}r@{}>{${}={}$\hfill}r}
$X_j$&$f_j$&\multicolumn{1}{c}{$f_jX_j$}\\
\hline
28&1&(1)(28)&28\\
27&0&(0)(27)&0\\
26&1&(1)(26)&26\\
25&2&(2)(25)&50\\
24&3&(3)(24)&72\\
23&4&(4)(23)&92\\
22&3&(3)(22)&66\\
21&0&(0)(21)&0\\
20&1&(1)(20)&20\\
19&2&(2)(19)&38\\
18&1&(1)(18)&18\\
17&0&(0)(17)&0\\
16&1&(1)(16)&16\\
15&0&(0)(15)&0\\
14&1&(1)(14)&14\\
\hline
&$n=20$&\hidewidth$\displaystyle\sum^{k}_{j=1}f_jX_j=440$\hidewidth\hfil
\end{tabular}
\end{frame}
\end{document}


Experiment with the size of the spacing until the result is satisfying

-

Make sure that all the lines have the same number of columns. -and only use \multicolumn when the cell is spanning more than one column.

\documentclass[10pt]{article}
\begin{document}

\begin{tabular}{ccr@{\hspace{1pt}=\hspace{1pt}}r}

$X_j$&$f_j$&\multicolumn{2}{c}{$f_jX_j$}\\

\hline

28&1&(1)(28)&28\\
27&0&(0)(27)&0\\
26&1&(1)(26)&26\\
25&2&(2)(25)&50\\
24&3&(3)(24)&72\\
23&4&(4)(23)&92\\
22&3&(3)(22)&66\\
21&0&(0)(21)&0\\
20&1&(1)(20)&20\\
19&2&(2)(19)&38\\
18&1&(1)(18)&18\\
17&0&(0)(17)&0\\
16&1&(1)(16)&16\\
15&0&(0)(15)&0\\
14&1&(1)(14)&14\\

\hline

& $n=20$ & $\displaystyle\sum^{k}_{j=1}f_jX_j$ & 440

\end{tabular}
\end{document}


-
Werner's answer is better than mine. – Hans-Peter E. Kristiansen Aug 28 '12 at 21:32