1

I have a very simple table with only a few cells.

\documentclass{article}
\usepackage{mwe}

\begin{document}

\begin{table}[ht]
\centering
\begin{tabular}{c|ccc}
  \hline
 Long Text Here & D & E & F \\ 
  \hline

\begin{center}\includegraphics[width=0.6\textwidth]{{example-image-a}}\end{center} & 100 & 200 & 300 \\ 
\hline
\begin{center}\includegraphics[width=0.6\textwidth]{{example-image-b}}\end{center} & 17 &  5 & 9898898 \\ 
\hline
\begin{center}\includegraphics[width=0.6\textwidth]{{example-image-c}}\end{center} & 2 & - &  8 \\ 
   \hline
\end{tabular}
\end{table}

\end{document}

I want to align all the texts in rows so that they horizontally and vertically centered.

I followed the example here which does exactly what I need to do. But I am having trouble incorporating the m{} function into my table. When I add {*{4}{m{0.4\textwidth}}} everything looks terrible and out of place.

How can I adopt m{} without breaking the table in this case? I don't quite understand how I can mix c and m together in order to keep everyting in center horizontally and vertically.

0

1 Answer 1

0

like this:

enter image description here

with help of adjustbox (for vertical centering of images and adding margins above/below them) and etoolbox (for patching Gin keys):

\documentclass{article}
\usepackage[export]{adjustbox}
\usepackage{etoolbox}


\begin{document}
    \begin{table}[ht]
    \centering
    \expandafter\patchcmd\csname Gin@ii\endcsname   % needed etoolbox
      {\setkeys {Gin}{#1}}
      {\setkeys {Gin}{width=0.6\linewidth,
                      valign=c, margin=0pt 6pt 0pt 6pt,#1}% settings from adjustbox
      }
      {}{}
\begin{tabular}{c|ccc}
  \hline
Sequence Model & D & E & F \\
  \hline
\includegraphics{example-image-a} & 100 & 200 & 300       \\
    \hline
\includegraphics{example-image-b} &  17 &   5 & 9898898   \\
    \hline
\includegraphics{example-image-c} &   2 & --  & 8         \\
   \hline
\end{tabular}
    \end{table}
\end{document}
2
  • Thank you. This is exactly what I need, but I still do not quite understand why D, E, F are not horizontally in the center. They seem quite off even though to my understanding they should not be given that `{c|ccc} is used, but I might have a wrong understanding of those parameters. Sorry, I have very basic knowledge in LaTeX!
    – xeyetopewu
    Feb 5, 2019 at 15:27
  • @xeyetopewu, the content of all columns are horizontally centered. probably you mean that are not vertically centered, since below them you see more space than above them. this seems so, because text in column headers D, E, F haven't letters which protrude baseline like j, p, q ... does (see first column header). if you like to have additional vertical space you can use \setlength\extrarowheight{2pt} from package array before tabular environment.
    – Zarko
    Feb 5, 2019 at 15:49

You must log in to answer this question.

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