# Center in a table

I draw the following table

$\begin{table}[h!] $\begin{array}{l|c} &0\hspace{0.7cm} 1\hspace{1cm}\dots s \\ \hline i&\beta_{0,i}\hspace{1cm} \beta_{1,i+1}\hspace{0.5cm}\dots\hspace{0.5cm}\beta_{s,i+s} \\ i+1&\beta_{0,i+1}\hspace{0.9cm} \beta_{1,i+2}\hspace{0.5cm}\dots\hspace{0.5cm}\beta_{s,i+s+1}\\ \vdots&\cdots\cdots\cdots\\\ j&\beta_{0,j}\hspace{1cm} \beta{1,j+1}\hspace{0.5cm}\dots\hspace{0.5cm}\beta_{s,j+s} \end{array}$ \caption{Labels need to be placed \emph{after} the caption.} \label{tab:table1} \end{table} \\$


But 1 is not on the first column, also $\beta_{0,i}$. Also 2 is not on the second column. How can I center them?

• Is there any reason for $\begin{table}? and \end{document}\\$? – user31729 Feb 10 '18 at 18:24
• Why all those hand-made horizontal spacings? What are you trying to achieve? – Bernard Feb 10 '18 at 18:47

Maybe you want to use five columns instead of only two:

\documentclass{article}
\begin{document}
$\begin{array}{l|cccc} & 0 & 1 & \dots & s \\ \hline i & \beta_{0,i} & \beta_{1,i+1} & \dots & \beta_{s,i+s} \\ i+1 & \beta_{0,i+1} & \beta_{1,i+2} & \dots & \beta_{s,i+s+1}\\ \vdots & \cdots & \cdots & & \cdots\\\ j & \beta_{0,j} & \beta_{1,j+1} & \dots & \beta_{s,j+s} \end{array}$
\end{document}


Just some improvements:

\documentclass{article}
\usepackage{mathtools, array}

\begin{document}

\begin{table}[h!]\setlength{\extrarowheight}{2pt}
$\begin{array}{@{}c|*{4}{c}@{}} &0 & 1 & \dots & s \\ \hline i &\beta_{0,i} & \beta_{1,i+1} & \dots & \beta_{s,i+s} \\ i+1&\beta_{0,i+1} & \beta_{1,i+2} & \dots & \beta_{s,i+s+1}\\ \vdots& \vdots & \vdots & & \vdots \\ j&\beta_{0,j} & \beta_{1,j+1} & \dots & \beta_{s,j+s} \end{array}$
\caption{Labels need to be placed \emph{after} the caption.}
\label{tab:table1}
\end{table}
\end{document}


I wouldn't use an unnumbered display-math environment (\[...\}) to "contain" the array environment. Instead, I'd use a \centering directive (and place the array environment in math mode). To give the array a less-cramped look, consider increasing the value of \arraystretch by one third or so.

\documentclass{article}
\begin{document}
\begin{table}[h!]
\centering
\renewcommand\arraystretch{1.33}
$\begin{array}{@{}c|cccc@{}} &0 & 1 & \dots & s \\ \hline i&\beta_{0,i} & \beta_{1,i+1} & \dots & \beta_{s,i+s} \\ i+1&\beta_{0,i+1}& \beta_{1,i+2} & \dots & \beta_{s,i+s+1}\\ \vdots& \cdots & \cdots & & \cdots \\ j&\beta_{0,j} & \beta_{1,j+1} & \dots & \beta_{s,j+s} \end{array}$
\caption{\texttt{\string\label} must be placed \emph{after} \texttt{\string\caption}}
\label{tab:table1}
\end{table}
\end{document}