Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Sep 20 '12 at 14:07

This question came from our site for professional and enthusiast programmers.

    
Check your documentation: You don't need the table environment. –  Martin Schröder Sep 19 '12 at 21:55
    
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Sep 20 '12 at 15:54

1 Answer 1

The table environment is merely a placeholder for a float using the table counter. However, it can contain anything - not necessarilty a tabular (even an image is fine, really). In this instance though, you don't need to let the tabular float, so you should use it as-is:

enter image description here

\documentclass{article}
\usepackage{enumerate}% http://ctan.org/pkg/enumerate
\usepackage{array}% http://ctan.org/pkg/array
\newcolumntype{M}{>{$}c<{$}}
\begin{document}
\begin{enumerate}[(a)]
  \item
  \begin{enumerate}[i.]
  \item
    \begin{tabular}{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
         & \multicolumn{1}{c}{} & & \uparrow & \\ 
    \end{tabular}
  \end{enumerate}
\end{enumerate}
\end{document}​

You don't really need the array package here, since you can post the entire tabular as a $\begin{array}{cc|ccc}...\end{array}$ and obtain the same result.

Other packages you might consider include enumitem for list management and booktabs for publishing-quality table constructions. Here's a take using the above suggestions:

enter image description here

\documentclass{article}
\usepackage{enumitem}% http://ctan.org/pkg/enumitem
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\begin{document}
\begin{enumerate}[label=(\alph*)]
  \item
  \begin{enumerate}[label=\roman*.]
  \item
    $\begin{array}{c c c c c}
        \toprule
        p & q & (p \rightarrow q) & \rightarrow & (q \rightarrow p) \\ \midrule
        0 & 0 & 1 & 1 & 1 \\ 
        0 & 1 & 1 & 0 & 0 \\
        1 & 0 & 0 & 1 & 1 \\  
        1 & 1 & 1 & 1 & 1 \\ 
        \bottomrule
         & \multicolumn{1}{c}{} & & \uparrow &
    \end{array}$
  \end{enumerate}
\end{enumerate}
\end{document}​

Vertical alignment is also adjustable using a [t] or [b] optional argument to either tabular or array. This would align the structure to either the top or the bottom line/row.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.