1

I am trying to insert a table with a caption inside an itemize environment. However I can't find a way to align the caption nor the table itself to the border of the outer environment.

I already tried scalebox, parbox, minipage, ..together with captionof..but still can't find a way to make it fit.

This is my code:

\documentclass[a4paper,12pt]{report}
\setlength{\paperheight}{297mm}
\setlength{\paperwidth}{210mm}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage[italian]{babel}
\usepackage[margin=1.2in]{geometry}
\usepackage{blkarray}
\usepackage{float}
\usepackage{subcaption}
\usepackage{caption}
\begin{document}

\begin{itemize}
    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis laoreet nunc. Integer vel turpis ut odio viverra malesuada. Pellentesque est leo, scelerisque eget eros eget, finibus luctus felis.
    \begin{table}[ht]
        \centering
        \resizebox{.85\textwidth}{!}{
            \begin{tabular}{|l|l|l|l|l|l|l|l|}
                \hline
                Type       & PCB & PCB & PCB & PCB & PCB & PCB & PCB \\ \hline
                Number     & 1   & 1   & 1   & 1   & 1   & 1   & 1   \\ \hline
                Number two & \multicolumn{7}{c|}{6}                  \\ \hline
            \end{tabular}
        }
        \caption{Cras sit amet leo ante. Nunc condimentum magna non ornare dignissim. Curabitur vitae porta nisi. Nunc tempor, diam non tempor suscipit, nulla nisl porta dui, in consectetur odio odio vitae magna.}
        \label{tabelladeltageopcb}
        \end{table}
        Fusce dignissim quis enim eget posuere. Nullam suscipit pulvinar magna sed pharetra. In in auctor nulla. Etiam in quam vitae dui luctus pellentesque ac vitae quam.
    \end{itemize}
\end{document}

Thanks in advance

  • I'm not really sure why the table, with its caption must go there. In my opinion it is the worst place, because it will be more difficult to find than if it is at top or bottom of page. The caption makes it easy to see what the table is about; the number is for referencing the table in the text. If a table must go in some place, then no caption is needed. – egreg Jan 8 '16 at 21:29
2

The only point of a table environment is to allow latex to float the table so here where you want it in the list, you do not want table

enter image description here

\documentclass[a4paper,12pt]{report}
\setlength{\paperheight}{297mm}
\setlength{\paperwidth}{210mm}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage[italian]{babel}
\usepackage[margin=1.2in]{geometry}
\usepackage{blkarray}
\usepackage{float}
\usepackage{subcaption}
\usepackage{caption}
\begin{document}

\begin{itemize}
    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis laoreet nunc. Integer vel turpis ut odio viverra malesuada. Pellentesque est leo, scelerisque eget eros eget, finibus luctus felis.

\begin{minipage}{\linewidth}
            \begin{tabular}{|l|l|l|l|l|l|l|l|}
                \hline
                Type       & PCB & PCB & PCB & PCB & PCB & PCB & PCB \\ \hline
                Number     & 1   & 1   & 1   & 1   & 1   & 1   & 1   \\ \hline
                Number two & \multicolumn{7}{c|}{6}                  \\ \hline
            \end{tabular}

        \captionof{table}{Cras sit amet leo ante. Nunc condimentum magna non ornare dignissim. Curabitur vitae porta nisi. Nunc tempor, diam non tempor suscipit, nulla nisl porta dui, in consectetur odio odio vitae magna.}
        \label{tabelladeltageopcb}
\end{minipage}

        Fusce dignissim quis enim eget posuere. Nullam suscipit pulvinar magna sed pharetra. In in auctor nulla. Etiam in quam vitae dui luctus pellentesque ac vitae quam.
    \end{itemize}
\end{document}
  • +1 for not using [H]. – egreg Jan 8 '16 at 21:30
0

Here is a way to go using the list parameters and the threeparttable environment:

\documentclass[a4paper,12pt]{report}
\setlength{\paperheight}{297mm}
\setlength{\paperwidth}{210mm}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage[italian]{babel}
\usepackage[margin=1.2in]{geometry}
\usepackage{blkarray}
\usepackage{float}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{threeparttable}
\begin{document}

\begin{itemize}
    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis laoreet nunc. Integer vel turpis ut odio viverra malesuada. Pellentesque est leo, scelerisque eget eros eget, finibus luctus felis.
    \begin{table}[ht]
        \centering
        \hskip\leftmargin\begin{threeparttable}
            \begin{tabular}{|l|*{7}{c|}}
                \hline
                Type & PCB & PCB & PCB & PCB & PCB & PCB & PCB \\ \hline
                Number & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ \hline
                Number two & \multicolumn{7}{c|}{6} \\ \hline
            \end{tabular}
    \caption{Cras sit amet leo ante. Nunc condimentum magna non ornare dignissim. Curabitur vitae porta nisi. Nunc tempor, diam non tempor suscipit, nulla nisl porta dui, in consectetur odio odio vitae magna.}
        \label{tabelladeltageopcb}
    \end{threeparttable}
    \end{table}
        Fusce dignissim quis enim eget posuere. Nullam suscipit pulvinar magna sed pharetra. In in auctor nulla. Etiam in quam vitae dui luctus pellentesque ac vitae quam.
    \end{itemize}

\end{document} 

enter image description here

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.