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}
Andrea
  • 99

2 Answers2

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}
JPi
  • 13,595
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}
Zarko
  • 296,517
  • 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 May 25 '17 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 May 25 '17 at 17:27
  • Super! But now the text is not anymore centered inside the cells – Andrea Jun 01 '17 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 Jun 01 '17 at 13:20