我想在 \enumerate 环境中插入一个 \table ,我有这样的事情:
\begin{enumerate}
\item Item 1.
\item Item 2.
\item \begin{table}[htbp]
\textbf{\caption{Table1 Caption}}
\centering
\begin{tabular}{c c}
\hline\hline
Value 1 & Value 2\\
\hline
r1c1 & r2c2\\
r2c1 & r2c2\\
r3c1 & r3c2\\
\hline
\end{tabular}
\label{table1}
\end{table}
\item \begin{table}[htbp]
\textbf{\caption{Table 2 Caption}}
\centering
\begin{tabular}{ccc}
\hline\hline
Value 1 & Value 2 & Value 3\\
\hline
r1c1 & r1c2 & r1c3\\
r2c1 & r2c2 & r2c3\\
r3c1 & r3c2 & r3c3\\
\end{tabular}
\label{table2}
\end{table}
\item \ref{table1} and \ref{table2}
\end{enumerate}
Run Code Online (Sandbox Code Playgroud)
但是当我编译乳胶文档时,\enumerate 数字不在桌子附近。此外,当我提到标签“table1”和“table2”时,它分别显示为 3 和 4(有关额外信息,这部分在 3.3 小节中,这是整个文档中仅有的两个表)。
我如何将 \table 环境与 \enumerate 环境一起使用。我见过人们只使用 \tabular 和 \enumerate 但我想使用 \table 因为它给了我一个简单的选项来定义 \caption 和 \label。
另外关于表格标签,我假设它与小节编号有关,但我真的无法弄清楚。
我真的很感激有关此事的任何帮助。
一个table环境是一个浮动。它并不意味着包含在其他环境中。
您可以使用这样的tabular环境:
\documentclass[a4paper, 11pt]{article}
\begin{document}
\begin{enumerate}
\item Item 1.
\item Item 2.
\item \begin{tabular}[t]{c c}
Value 1 & Value 2\\
\hline
r1c1 & r2c2\\
r2c1 & r2c2\\
r3c1 & r3c2\\
\hline
\end{tabular}
\item \begin{tabular}[t]{ccc}
Value 1 & Value 2 & Value 3\\
\hline
r1c1 & r1c2 & r1c3\\
r2c1 & r2c2 & r2c3\\
r3c1 & r3c2 & r3c3\\
\end{tabular}
\end{enumerate}
\end{document}
Run Code Online (Sandbox Code Playgroud)
输出将如下所示:
请注意,如果您尝试将 tp put\hline放在桌子的顶部,垂直对齐看起来会很奇怪。
编辑 1:您\label几乎可以将 a 放在您喜欢的任何地方,但除非设置了变量,否则它不会将自己称为“表”。您必须深入研究 LaTeX 的内部结构才能了解它是如何完成的。
至少有两个包(capt-of和caption)提供一个\captionof命令来定义一个figure或table环境之外的标题。