4

I'm struggling into making a table with some images inside adn I would like to have them vertically and horizontal centred (both the image and the text). I'vw tried a lot of suggested example here but nothing work. Can you help me?

enter image description here

This is the table code:

\begin{table}
\centering

\caption{text centered table}
\label{fGO_table}
\begin{tabular}{ m{0.20\textwidth}  m{0.1\textwidth}  p{0.55\textwidth} }      % centered columns (3 columns) 
    \hline\hline                                      %inserts double horizontal lines 
    ref  & code & structure \\ [0.5ex] % inserts table heading 
    \hline
    
    ref1    & GO2 &\begin{center} \includegraphics[scale=0.8]{immagini/MM/AMMON.jpg} 
    \end{center}                    
    
    \\ 
    \hline  
    ref2 
    & GO3 &\begin{center}
        \includegraphics[scale=0.8]{immagini/MM/ED.jpg}\end{center} \\
    \hline  
    ref3
    & GO3&
     \begin{center}
        \includegraphics[scale=0.8]{immagini/MM/TEPA.jpg}\end{center}\\
    \hline  
    ref4
    & GO5&
     \begin{center}
        \includegraphics[scale=0.8]{immagini/MM/pN.jpg}\end{center} \\
    \hline  
    ref5
    &  GO7&
    \begin{center}
        \includegraphics[scale=0.8]{immagini/MM/MEL.jpg}\end{center}\\
    \hline  
\end{tabular}
\end{table}
0
6

Assuming that you want your imges horizontally and vertically centered inside of a fixed width column, I suggest the following:

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{array}
\usepackage[export]{adjustbox}

\usepackage[column=0]{cellspace}
\setlength{\cellspacetoplimit}{0.5\tabcolsep}
\setlength{\cellspacebottomlimit}{\cellspacetoplimit}
\begin{document}

\begin{table}
\centering

\caption{text centered table}
\label{fGO_table}
\begin{tabular}{ 0{p{0.20\textwidth}}  0{p{0.1\textwidth}}  0{wc{0.55\textwidth}} }      % centered columns (3 columns) 
    \hline\hline                                      %inserts double horizontal lines 
    ref  & code & structure \\ [0.5ex] % inserts table heading 
    \hline
    ref1 & GO2 & \includegraphics[scale=0.8,valign=c]{immagini/MM/AMMON.jpg} \\ 
    \hline  
    ref2 
    & GO3 &\includegraphics[scale=0.8,valign=c]{immagini/MM/ED.jpg} \\
    \hline  
    ref3
    & GO3& \includegraphics[scale=0.8,valign=c]{immagini/MM/TEPA.jpg}\\
    \hline  
    ref4
    & GO5& \includegraphics[scale=0.8,valign=c]{immagini/MM/pN.jpg} \\
    \hline  
    ref5
    &  GO7& \includegraphics[scale=0.8,valign=c]{immagini/MM/MEL.jpg}\\
    \hline  
\end{tabular}
\end{table}

\end{document}
4
  • It has worked!!!!! thank you, just a question, I do not understand the meaning of the 0 here, 0{m{0.20\textwidth}} – Matteo Dec 30 '20 at 19:46
  • 1
    Depending on the output, valign=C might work better than valign=c. – Werner Dec 30 '20 at 19:47
  • @Werner: C instead of c seems to work in combination with m type columns, while c results in vertically centered contents when used in combination with p type columns (or as in this case with a wc) – leandriis Dec 30 '20 at 22:02
  • @Matteo: 0 here comes from the cellspace package (due to the option column=0). I added this package in order to add some (3pt = 0.5\tabcolsep) white space above and below each image. Otherwise the images would touch the horizontal lines. Fee free to adjust this space to your needs or to remove the package and its setting entirely. – leandriis Dec 30 '20 at 22:02
4

With employing booktabs, use macro \adjustimage defined in the adjustbox package and keys Gin the code of table become much shorter and clearer:

\documentclass{article}
\usepackage{array, booktabs}
\usepackage[demo,
            export]{adjustbox}  % it also load graphicx
\usepackage[skip=1ex]{caption}

\begin{document}
    \begin{table}[ht]
    \centering
\caption{text centered table}
\label{fGO_table}
    \setkeys{Gin}{}
    \adjustboxset{scale=0.8, valign=c}
\begin{tabular}{w{c}{0.20\textwidth} 
                w{c}{0.10\textwidth} 
                c}      
    \toprule                                   
ref     & code  & structure                             \\
    \midrule
ref1    & GO2   & \adjustimage{}{immagini/MM/AMMON.jpg} \\
    \midrule
ref2    & GO3   & \adjustimage{}{immagini/MM/ED.jpg}    \\
    \midrule
ref3    & GO3   & \adjustimage{}{immagini/MM/TEPA.jpg}  \\
    \midrule
ref4    & GO5   & \adjustimage{}{immagini/MM/pN.jpg}    \\
    \midrule
ref5    & GO7   & \adjustimage{}{immagini/MM/MEL.jpg}   \\
    \bottomrule
\end{tabular}
    \end{table}
\end{document}

enter image description here

1
  • Thank you very much – Matteo Jan 2 at 19:56

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.