我画了下表
$\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}
\\$
但是 1 也不在第一列$\beta_{0,i}$
。2 也不在第二列。我怎样才能将它们居中?
答案1
也许您想使用五列而不是仅两列:
\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}
答案2
只是一些改进:
\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}
答案3
我不会使用未编号的 display-math 环境 ( \[...\}
) 来“包含”array
环境。相反,我会使用\centering
指令(并将array
环境置于数学模式)。为了让数组看起来不那么拥挤,可以考虑将 的值增加\arraystretch
三分之一左右。
\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}