\table 在乳胶中的 \enumerate 环境中
\table in \enumerate environment in latex
我想在 \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}
但是当我编译 latex 文档时,\enumerate 数字不在 table 附近。此外,当我引用标签 "table1" 和 "table2" 时,它分别显示为 3 和 4(有关额外信息,这部分在第 3.3 小节中,这是整个中仅有的两个 table文档)。
如何在 \enumerate 环境中使用 \table 环境。我见过人们只使用 \tabular 和 \enumerate 但我想使用 \table 因为它给了我一个简单的选项来定义 \caption 和 \label.
另外关于 table 标签,我假设它与小节号有关,但我真的弄不明白。
对于此事的任何帮助,我将不胜感激。
一个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}
输出将如下所示:
请注意,如果您尝试将 \hline
放在 table 之上,垂直对齐看起来会很奇怪。
编辑 1:你几乎可以把 \label
放在任何你喜欢的地方,但它不会将自己称为 "Table" 除非变量是放。您必须深入了解 LaTeX 的内部结构才能了解它是如何完成的。
至少有两个软件包 (capt-of and caption) 提供 \captionof
命令来定义 figure
或 table
环境之外的标题。
我想在 \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}
但是当我编译 latex 文档时,\enumerate 数字不在 table 附近。此外,当我引用标签 "table1" 和 "table2" 时,它分别显示为 3 和 4(有关额外信息,这部分在第 3.3 小节中,这是整个中仅有的两个 table文档)。
如何在 \enumerate 环境中使用 \table 环境。我见过人们只使用 \tabular 和 \enumerate 但我想使用 \table 因为它给了我一个简单的选项来定义 \caption 和 \label.
另外关于 table 标签,我假设它与小节号有关,但我真的弄不明白。
对于此事的任何帮助,我将不胜感激。
一个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}
输出将如下所示:
请注意,如果您尝试将 \hline
放在 table 之上,垂直对齐看起来会很奇怪。
编辑 1:你几乎可以把 \label
放在任何你喜欢的地方,但它不会将自己称为 "Table" 除非变量是放。您必须深入了解 LaTeX 的内部结构才能了解它是如何完成的。
至少有两个软件包 (capt-of and caption) 提供 \captionof
命令来定义 figure
或 table
环境之外的标题。