I have a problem trying to add a table in an enumerate
environment in LaTeX.
I want the table to act as if it were just another piece of text. i.e. showing up exactly right next to the \item
in an enumerate
environment.
I currently use this to create my table (M
is to have a 'math' table):
\begin{enumerate}[(a)]
\item
\begin{enumerate}[i.]
\item
\begin{table}[h!]
\begin{tabular}{M M|M M M M M M M}
\hline
p & q & (p & \rightarrow & q) & \rightarrow & (q & \rightarrow & p) \\ \hline
0 & 0 & ~ & 1 & ~ & 1 & ~ & 1 & ~ \\
0 & 1 & ~ & 1 & ~ & 0 & ~ & 0 & ~ \\
1 & 0 & ~ & 0 & ~ & 1 & ~ & 1 & ~ \\
1 & 1 & ~ & 1 & ~ & 1 & ~ & 1 & ~ \\
\hline
~ & ~ & ~ & ~ & ~ & \uparrow & ~ & ~ & ~ \\
\end{tabular}
\end{table}
\end{enumerate}
\end{enumerate}
But when the code is compiled the table shows up outside of the enumeration.
Best Answer
The
table
environment is merely a placeholder for a float using thetable
counter. However, it can contain anything - not necessarilty atabular
(even an image is fine, really). In this instance though, you don't need to let thetabular
float, so you should use it as-is:You don't really need the
array
package here, since you can post the entiretabular
as a$\begin{array}{cc|ccc}...\end{array}$
and obtain the same result.Other packages you might consider include
enumitem
for list management andbooktabs
for publishing-quality table constructions. Here's a take using the above suggestions:Vertical alignment is also adjustable using a
[t]
or[b]
optional argument to eithertabular
orarray
. This would align the structure to either thet
op or theb
ottom line/row.