0

When creating a table in latex and inserting a text inside a specific cell, if the text is long, this is the result:

enter image description here

Even if there is enough space in the cell to contain the whole sentence. Moreover, I would like to like to start writing from the upper-right corner of the cell and not the bottom-right.

The code that gives me this error is here reported:

\begin{center}
    \begin{tabular}{ |c| c| }
    \hline
        {\includegraphics[scale=0.35,keepaspectratio]{png_Images/read_actor.png}}
        & 
        \begin{tabular}[]{@{}l@{}}
        This actor is in charge of performing the action of reading
        the image from the memory. 
        \end{tabular}
        \\ 
        \hline
        {\includegraphics[scale=0.3,keepaspectratio]{png_Images/tiling.png}} 
        & cap2  \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio]{png_Images/filter.png}} 
        & cap3  \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio]{png_Images/merge.png}}
        & cap4  \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio]{png_Images/save.png}} 
        & cap5  \\
    \hline
    \end{tabular}
\end{center}

Any suggestion?

3

You can load adjustbox and use valign=c with \includegraphics, and m{some length} for the second column. Last, I added some vertical padding around cells in the 1st column with the cellspace package.

\documentclass{article}
\usepackage{array, cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}
\usepackage[demo]{graphicx}%
\usepackage[export]{adjustbox} 

\begin{document}

\begin{center}
    \begin{tabular}{ |Sc| m{0.4\linewidth}| }
    \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign = c]{png_Images/read_actor.png}}
        &
        This actor is in charge of performing the action of reading
        the image from the memory.
        \\
        \hline
        {\includegraphics[scale=0.3,keepaspectratio, valign=c]{png_Images/tiling.png}}
        & cap2 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=c]{png_Images/filter.png}}
        & cap3 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=c]{png_Images/merge.png}}
        & cap4 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=c]{png_Images/save.png}}
        & cap5 \\
    \hline
    \end{tabular}
\end{center}

\end{document} 

enter image description here

  • LaTeX Error: Option clash for package graphicx. – Leos313 Sep 5 at 12:01
  • the solution give error on Overleaf – Leos313 Sep 5 at 12:15
  • 1
    Remove the demo option – it was there jut because I don't have your graphic files. What error do you have, other than the option clash? – Bernard Sep 5 at 12:21
  • +1 no error now. – Leos313 Sep 5 at 12:54
1

Here is a variant that uses tabularx X type column for the second column as well as a different vertical alignment (valign=t). Similar to Bernard, I have also used the cellspace package to add a symmetric white border around the images (=white space above and below equals \tabcolsep)

enter image description here

\documentclass{article}
\usepackage{array, cellspace}
\setlength{\cellspacetoplimit}{\tabcolsep}
\setlength{\cellspacebottomlimit}{\tabcolsep}
\usepackage[demo]{graphicx}%
\usepackage[export]{adjustbox} 
\usepackage{tabularx}

\begin{document}

\begin{center}
    \begin{tabularx}{\textwidth}{ |Sc| X | }
    \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign = t]{png_Images/read_actor.png}}
        &
        This actor is in charge of performing the action of reading
        the image from the memory.
        \\
        \hline
        {\includegraphics[scale=0.3,keepaspectratio, valign=t]{png_Images/tiling.png}}
        & cap2 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=t]{png_Images/filter.png}}
        & cap3 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=t]{png_Images/merge.png}}
        & cap4 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=t]{png_Images/save.png}}
        & cap5 \\
    \hline
    \end{tabularx}
\end{center}

\end{document} 
  • Package array Error: Illegal pream-token (S): `c' used. – Leos313 Sep 5 at 12:04
  • @Leos313: with the exact same example code from my answer or in your actual document? – leandriis Sep 5 at 12:08
  • ok, deleting the S avoid the problem and the code is correctly compiled – Leos313 Sep 5 at 12:08
  • 1
    In your actual document, make sure, you load the cellspace` package. – leandriis Sep 5 at 12:09
  • 1
    @Leos313: If you delete the S from the code, the spacing of the images will be different. There will be no white space above and below the images. If you on the other hand add \usepackage{cellspace} \setlength{\cellspacetoplimit}{\tabcolsep} \setlength{\cellspacebottomlimit}{\tabcolsep} to your preamble and keep the S, there is a small white space all around the image (as you can see in the screenshot in my answer). So, the output will in fact not be the same. – leandriis Sep 5 at 12:13

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.