2

I have a problem with a table that does not fit into the page but it goes out on the right, where is my mistake?

\begin{table}[H]
\begin{tabular}{|c|c|c|c|c|}
\hline
\textbf{Interviewee} & Name1 & Name 2 & Name3 & Name 4 \\ \hline
\textbf{Picture} & \includegraphics[width=2cm, height=2cm]
{figures/img1.jpg} & \includegraphics[width=2cm, height=2cm]
{figures/img2.jpg} & \includegraphics[width=2cm, height=2cm]
{figures/img3.JPG} & \includegraphics[width=2cm, height=2cm]
{figures/img4.png} \\ \hline
\textbf{Company} & Name 1 & Name 2 & Name 3 & Name 4 \\ \hline
\textbf{Logo} & \includegraphics[width=0.2\textwidth]
{figures/img5.png} & \includegraphics[width=0.2\textwidth]
{figures/img6.png} & \includegraphics[width=0.2\textwidth]
{figures/img7.png} & \includegraphics[width=0.2\textwidth]
{figures/img8.png} \\ \hline
\textbf{Position} &  & &  & \\ \hline
\textbf{Value added} & &  &  & \\ \hline
\textbf{Purpose} & Input & Input & Application & Application \\ \hline
\end{tabular}
\caption{My caption}
\label{my-label}
\end{table}
3
  • 1
  • Welcome to TeX.SE! Your table is wider than text width. For help you we need complete small document with your table with \documentclass{...}˙` on beginning and \end{document} on the end and all packages related to your table and page layout.
    – Zarko
    Commented May 24, 2017 at 13:10
  • avoid doing width=2cm, height=2cm specifying both directions can distort the image, just specify one or the other Commented May 24, 2017 at 14:38

2 Answers 2

1

enter image description here

used: adjustox for image positioning in table cells, tabularx to fit table in \textwidth:

\documentclass{memoir}
\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}

%---------------------------------------------------------------%
\usepackage{showframe}% for show page layout
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{table}
    \setlength\tabcolsep{0pt}
    \centering
\begin{tabularx}{\linewidth}{|>{\bfseries\centering}X|c|c|c|c|}
\hline
Interviewee & Name 1& Name 2 & Name3 & Name 4 \\ \hline
Picture     & \includegraphics[width=2cm, height=2cm, margin=3pt,valign=m]
{figures/img1.jpg}  & \includegraphics[width=2cm, height=2cm, margin=3pt,valign=m]
{figures/img2.jpg}  & \includegraphics[width=2cm, height=2cm, margin=3pt,valign=m]
{figures/img3.JPG}  & \includegraphics[width=2cm, height=2cm, margin=3pt,valign=m]
{figures/img4.png} \\ \hline
Company     & Name 1 & Name 2 & Name 3 & Name 4 \\ \hline
Logo        & \includegraphics[width=2cm, margin=2pt,valign=m]
{figures/img5.png}  & \includegraphics[width=2cm, margin=3pt,valign=m]
{figures/img6.png}  & \includegraphics[width=2cm, margin=3pt,valign=m]
{figures/img7.png}  & \includegraphics[width=2cm, margin=3pt,valign=m]
{figures/img8.png} \\ \hline
Position    &   &   &   & \\ \hline
Value added &   &   &   & \\ \hline
Purpose     & Input & Input & Application & Application \\ \hline
\end{tabularx}
\caption{My caption}
\label{my-label}
\end{table}
\end{document}

Addendum: in the case, that below of images are longer text in more lines, than the columns for pictures had to be derivative of X column type. For example: >{\RaggedRight}X:

enter image description here

\documentclass{memoir}
\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}
\usepackage{ragged2e} % <-- new


\begin{document}
\begin{table}
    \setlength\tabcolsep{3pt}
    \centering
\begin{tabularx}{\linewidth}{|>{\bfseries}c|*{4}{>{\RaggedRight}X|}}% <-- changed
\hline
Interviewee & Name 1& Name 2 & Name3 & Name 4 \\ \hline
Picture     & \includegraphics[width=2cm, height=2cm, margin=3pt,valign=m]
{figures/img1.jpg}  & \includegraphics[width=2cm, height=2cm, margin=3pt,valign=m]
{figures/img2.jpg}  & \includegraphics[width=2cm, height=2cm, margin=3pt,valign=m]
{figures/img3.JPG}  & \includegraphics[width=2cm, height=2cm, margin=3pt,valign=m]
{figures/img4.png} \\ \hline
Company     & Name 1 & Name 2 & Name 3 & Name 4 \\ \hline
Logo        & \includegraphics[width=2cm, margin=2pt,valign=m]
{figures/img5.png}  & \includegraphics[width=2cm, margin=3pt,valign=m]
{figures/img6.png}  & \includegraphics[width=2cm, margin=3pt,valign=m]
{figures/img7.png}  & \includegraphics[width=2cm, margin=3pt,valign=m]
{figures/img8.png} \\ \hline
Position    &   &   &   & \\ \hline
Value added &   &   &   & \\ \hline
Purpose     & Input & Input & Application & longer description od application \\ \hline
\end{tabularx}
\caption{My caption}
\label{my-label}
\end{table}
\end{document}
4
  • This is perfect thanks, but why it puts the table in another page? And in the rows position and value added I need to write some text that probably need to be automatic wrapped, because it's made of few words, how is it possible?
    – Andrea
    Commented May 25, 2017 at 13:59
  • @Andrea, to first question: I don't know. If on the page, where you insert your table is not enough room for it, than it float on the next page (that is fundamental advantage of (La)TeX. For second question: in which column you like to wrap text in more lines? below images? if this is a case, and if in the first column is only text as it is now, this can be simply accomplished with (inter)change column type. I will add addendum to my answer for this case.
    – Zarko
    Commented May 25, 2017 at 17:27
  • Super! But now the text is not anymore centered inside the cells
    – Andrea
    Commented Jun 1, 2017 at 13:12
  • just replace \RaggedRight with\Centering, e.g.: >{\RaggedRight}X with >{\Centering}X. if you satisfied with answer, you can accept it :)
    – Zarko
    Commented Jun 1, 2017 at 13:20
2

\textwidth is the width of all the text. You have four images that are of width 0.2\textwidth each so the images are together already almost the width of the entire text block. Then you have an additional column and padding, so your table is wider than the text block and hence protrudes into the right margin. Simply reduce the width of the included images.

\documentclass{article}


\usepackage{float}
\usepackage{graphicx}

\begin{document}

\begin{table}[H]
\begin{tabular}{|c|c|c|c|c|}
\hline
\textbf{Interviewee} & Name1 & Name 2 & Name3 & Name 4 \\ \hline
\textbf{Picture} & \includegraphics[width=2cm, height=2cm]
{example-image-a} & \includegraphics[width=2cm, height=2cm]
{example-image-a} & \includegraphics[width=2cm, height=2cm]
{example-image-a} & \includegraphics[width=2cm, height=2cm]
{example-image-a} \\ \hline
\textbf{Company} & Name 1 & Name 2 & Name 3 & Name 4 \\ \hline
\textbf{Logo} & \includegraphics[width=0.15\textwidth]
{example-image-a} & \includegraphics[width=0.15\textwidth]
{example-image-a} & \includegraphics[width=0.15\textwidth]
{example-image-a} & \includegraphics[width=0.15\textwidth]
{example-image-a} \\ \hline
\textbf{Position} &  & &  & \\ \hline
\textbf{Value added} & &  &  & \\ \hline
\textbf{Purpose} & Input & Input & Application & Application \\ \hline
\end{tabular}
\caption{My caption}
\label{my-label}
\end{table}

\end{document}
4
  • Plus it's usually better to avoid using [H] in tables and figures, since it prevents them from floating. Try [h] instead.
    – JPi
    Commented May 24, 2017 at 13:52
  • or rather [htp] never [h] (which usually just generates a warning that it is being changed) Commented May 24, 2017 at 16:34
  • Isn't [htp] the default? What about [h!]?
    – JPi
    Commented May 24, 2017 at 16:44
  • no, in most classes the default is tbp [h!] like [h] will usually give a warning that it is being converted to [!ht] Commented May 24, 2017 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .