Text FormattingFit Tables or pictures into list items

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Jan Borowiec
Posts: 5
Joined: Sun Aug 09, 2020 9:31 pm

Fit Tables or pictures into list items

Post by Jan Borowiec »

I often need to create a table or picture in a list item. The result is that such a table or picture behaves as
if it were no part of the list and uses the whole pages textwidth.
What shall I do to solve this problem.
Best regards, Jan

Example:

Code: Select all

\NeedsTeXFormat{LaTeX2e}
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\pagestyle{empty}

\begin{document}

\paragraph{sample.}\ \ 
Level 1
\begin{enumerate}
  \item Level 2-1
    \begin{itemize}
      \item Level 3-1
      \item Level 3-2
        \begin{table}[thb]
          \begin{tabular}{|c|c|c|c|} \hline
                  AAAAAA & BBBBBB & CCCCCC & DDDDDD \\ \hline
          \end{tabular}
          \caption{Triumph! Triumpf! Du edles Paar!
           Besieget hast du die Gefahr!
           Der Isis Weihe ist nun dein!
           Kommt, kommt, tretet in den Tempel ein!}
        \end{table}
      \item Level 3-3
    \end{itemize}
  \item Level 2-2
\end{enumerate}
\end{document}
Last edited by cgnieder on Sun Aug 23, 2020 8:13 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Fit Tables or pictures into list items

Post by Bartman »

You could have simply added the example to your older topic instead of starting a new one for the same problem.

Code: Select all

\documentclass[a4paper]{article}
%\usepackage[utf8]{inputenc}% issue 28 in ltnews on CTAN
\usepackage[T1]{fontenc}
\usepackage{caption}% needed for \captionof command
\usepackage{showframe}% shows the page layout

\pagestyle{empty}

\begin{document}
\paragraph{sample.} Level 1
\begin{enumerate}
    \item Level 2-1
    \begin{itemize}
        \item Level 3-1
        \item Level 3-2

        \medskip
        \begin{minipage}{\linewidth}
            \begin{tabular}{|*4{c|}} \hline
            AAAAAA & BBBBBB & CCCCCC & DDDDDD \\ \hline
            \end{tabular}
            \captionof{table}{Triumph! Triumpf! Du edles Paar!
            Besieget hast du die Gefahr!
            Der Isis Weihe ist nun dein!
            Kommt, kommt, tretet in den Tempel ein!}
        \end{minipage}
        \item Level 3-3
    \end{itemize}
    \item Level 2-2
\end{enumerate}
\end{document}

Read the LaTeX2e unofficial reference manual to find out what the \NeedsTeXFormat command does before you use it (from a template).

I'd also like to recommend checking out the booktabs package.
Post Reply