3

I'm trying to put a table inside a list environment but without success. I'd like to have the table inside the item (matching \linewidth) and not floating in the next page.

\begin{description}
    \item[Lorem ipsum] \hfill \\
        Lorem ipsum dolor sit amet...
    \item[Lorem ipsum] \hfill \\
        \begin{table}[h]
            \centering
            \caption{Foobar}
            \label{tab:foobar}
            \begin{tabular}{@{}ll@{}}
                \toprule
                \textbf{foo} & \textbf{bar} \\
                \midrule
                Lorem ipsum & foo \\
                Lorem ipsum & bar \\
                \bottomrule
            \end{tabular}
        \end{table}
\end{description}

How can this be achieved?

2
  • Remove the table environment. Feb 11, 2014 at 0:17
  • Well, it is difficulty to help you without the code to produce the error. Also if there is no space enough to insert the table, no way, it will be inserted after.
    – Sigur
    Feb 11, 2014 at 0:17

2 Answers 2

3

If you really want to leave the table as is, inside the description environment, you can avoid it to float simply replacing the floating specifier h with the H provided by the the float package.

MWE:

\documentclass{article}
\usepackage{booktabs}
\usepackage{float} % defines the H specifier

\begin{document}
\begin{description}
    \item[Lorem ipsum] \hfill \\
        Lorem ipsum dolor sit amet...
    \item[Lorem ipsum] \hfill \\
        \begin{table}[H]
            \centering
            \caption{Foobar}
            \label{tab:foobar}
            \begin{tabular}{@{}ll@{}}
                \toprule
                \textbf{foo} & \textbf{bar} \\
                \midrule
                Lorem ipsum & foo \\
                Lorem ipsum & bar \\
                \bottomrule
            \end{tabular}
        \end{table}
\end{description}
\end{document} 

Output:

enter image description here

1
  • The specifier H did the trick! Thanks. Feb 11, 2014 at 9:23
3

You don't want table to float. Then remove the table environment. You can have the caption with the help of \captionof macro from either caption or capt-of packages.

\documentclass{article}
\usepackage{capt-of,booktabs}
\begin{document}
  \begin{description}
    \item[Lorem ipsum] \hfill \\
        Lorem ipsum dolor sit amet...
    \item[Lorem ipsum] \hfill \\
            \begin{minipage}{\linewidth}
            \centering
            \captionof{table}{Foobar}
            \label{tab:foobar}
            \begin{tabular}{@{}ll@{}}
                \toprule
                \textbf{foo} & \textbf{bar} \\
                \midrule
                Lorem ipsum & foo \\
                Lorem ipsum & bar \\
                \bottomrule
            \end{tabular}
        \end{minipage}
\end{description}
\end{document}

enter image description here

2
  • I've tried your method before and it has some faults: caption is not aligned with the table; can't control table width; vertical space between caption and the table is non existent. Feb 11, 2014 at 9:21
  • @RenatoRodrigues My method works too ;) See the edited answer.
    – user11232
    Feb 11, 2014 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.