我有三个表格,我想在它们下面使用一个标题。我尝试了以下操作,但除了标题外什么都没有打印出来 -
\begin{figure}[!h]
\begin{table}[h]
\centering
\begin{minipage}[t]{0.3\linewidth}
\begin{tabular}[t]{|c | c | c | c |}
\hline
State & $1$-step \\ \hline
$\ket{n, \leftarrow, 0}$ & $\leftarrow$ \\
$\ket{n, \leftarrow, 1}$ & $\rightarrow$ \\
$\ket{n, \rightarrow, 0}$ & $\rightarrow$ \\
$\ket{n, \rightarrow, 1}$ & $\leftarrow$ \\
\hline
\end{tabular}
\end{minipage}
\begin{minipage}[t]{0.3\linewidth}
\begin{tabular}[t]{|c | c | c | c |}
\hline
State & $2$-step \\ \hline
$\ket{n, \leftarrow, \leftarrow, 0}$ & $\leftarrow$ \\
$\ket{n, \leftarrow, \leftarrow, 1}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \rightarrow, 0}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \rightarrow, 1}$ & $\leftarrow$ \\ \hline
\hline
\end{tabular}
\end{minipage}
\begin{minipage}[t]{0.3\linewidth}
\begin{tabular}[t]{|c | c | c | c |}
\hline
State & $3$-step \\ \hline
$\ket{n, \leftarrow, \leftarrow, \leftarrow, 0}$ & $\leftarrow$ \\
$\ket{n, \leftarrow, \leftarrow, \leftarrow, 1}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \leftarrow, \rightarrow, 0}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \leftarrow, \rightarrow, 1}$ & $\leftarrow$ \\
\hline
\end{tabular}
\end{minipage}
\end{table}
\caption{Directions}
\end{figure}
如果我删除了图形和 begin{figure}、end{figure} 和 caption{} 标签,则表格会显示,但没有标题。那么如何才能让表格与标题一起显示呢?
答案1
你不能真的嵌套浮动环境(这在逻辑上没有意义)。这是主要问题,可能源于你认为你需要环境table
才能放置tabular
。事实并非如此。您可能想要以下内容:
\documentclass{article}
\usepackage{braket}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}[t]{| c | c |}
\hline
State & $1$-step \\ \hline
$\ket{n, \leftarrow, 0}$ & $\leftarrow$ \\
$\ket{n, \leftarrow, 1}$ & $\rightarrow$ \\
$\ket{n, \rightarrow, 0}$ & $\rightarrow$ \\
$\ket{n, \rightarrow, 1}$ & $\leftarrow$ \\
\hline
\end{tabular}\hfill%
\begin{tabular}[t]{| c | c |}
\hline
State & $2$-step \\ \hline
$\ket{n, \leftarrow, \leftarrow, 0}$ & $\leftarrow$ \\
$\ket{n, \leftarrow, \leftarrow, 1}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \rightarrow, 0}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \rightarrow, 1}$ & $\leftarrow$ \\
\hline
\end{tabular}\hfill%
\begin{tabular}[t]{| c | c |}
\hline
State & $3$-step \\ \hline
$\ket{n, \leftarrow, \leftarrow, \leftarrow, 0}$ & $\leftarrow$ \\
$\ket{n, \leftarrow, \leftarrow, \leftarrow, 1}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \leftarrow, \rightarrow, 0}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \leftarrow, \rightarrow, 1}$ & $\leftarrow$ \\
\hline
\end{tabular}
\caption{Directions}
\end{table}
\end{document}
您可能还对以下方面感兴趣booktabs
执行:
\documentclass{article}
\usepackage{braket,booktabs}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}[t]{c c}
\toprule
State & $1$-step \\ \midrule
$\ket{n, \leftarrow, 0}$ & $\leftarrow$ \\
$\ket{n, \leftarrow, 1}$ & $\rightarrow$ \\
$\ket{n, \rightarrow, 0}$ & $\rightarrow$ \\
$\ket{n, \rightarrow, 1}$ & $\leftarrow$ \\
\bottomrule
\end{tabular}\hfill%
\begin{tabular}[t]{c c}
\toprule
State & $2$-step \\ \midrule
$\ket{n, \leftarrow, \leftarrow, 0}$ & $\leftarrow$ \\
$\ket{n, \leftarrow, \leftarrow, 1}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \rightarrow, 0}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \rightarrow, 1}$ & $\leftarrow$ \\
\bottomrule
\end{tabular}\hfill%
\begin{tabular}[t]{c c}
\toprule
State & $3$-step \\ \midrule
$\ket{n, \leftarrow, \leftarrow, \leftarrow, 0}$ & $\leftarrow$ \\
$\ket{n, \leftarrow, \leftarrow, \leftarrow, 1}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \leftarrow, \rightarrow, 0}$ & $\rightarrow$ \\
$\ket{n, \leftarrow, \leftarrow, \rightarrow, 1}$ & $\leftarrow$ \\
\bottomrule
\end{tabular}
\caption{Directions}
\end{table}
\end{document}
tabular
顺便说一句:您也可以将整个表格放到一张桌子上。
答案2
除了去掉table
和minipage
“包装器”之外,您还可以使用array
环境而不是tabular
环境。我建议这样做,因为表格的内容都是数学模式,而array
环境是用于数学材料的。(tabular
相比之下,环境是用于主要包含文本的表格的。)我认为,能够省去所有这些$
符号可以大大简化代码的外观。
PS 我不清楚您是否希望整体浮动环境为figure
或类型table
。在示例中,我选择了figure
,但这可能不是您喜欢的。如果您希望标题列表为“表格”而不是“图形”,只需更改浮动环境的类型即可。
\documentclass{article}
\usepackage{braket,amsmath} % 'amsmath' for `\text` macro
\begin{document}
\begin{figure}[ht]
$ % start math mode
\begin{array}[t]{|c | c | c | c |}
\hline
\text{State} & \text{1-step} \\ \hline
\ket{n, \leftarrow, 0} & \leftarrow \\
\ket{n, \leftarrow, 1} & \rightarrow \\
\ket{n, \rightarrow, 0} & \rightarrow \\
\ket{n, \rightarrow, 1} & \leftarrow \\
\hline
\end{array}
\hspace*{\fill}
\begin{array}[t]{|c | c | c | c |}
\hline
\text{State} & \text{2-step} \\ \hline
\ket{n, \leftarrow, \leftarrow, 0} & \leftarrow \\
\ket{n, \leftarrow, \leftarrow, 1} & \rightarrow \\
\ket{n, \leftarrow, \rightarrow, 0} & \rightarrow \\
\ket{n, \leftarrow, \rightarrow, 1} & \leftarrow \\ \hline
\end{array}
\hspace*{\fill}
\begin{array}[t]{|c | c | c | c |}
\hline
\text{State} & \text{3-step} \\ \hline
\ket{n, \leftarrow, \leftarrow, \leftarrow, 0} & \leftarrow \\
\ket{n, \leftarrow, \leftarrow, \leftarrow, 1} & \rightarrow \\
\ket{n, \leftarrow, \leftarrow, \rightarrow, 0} & \rightarrow \\
\ket{n, \leftarrow, \leftarrow, \rightarrow, 1} & \leftarrow \\
\hline
\end{array}
$ % end math mode
\caption{Directions}
\end{figure}
\end{document}