1

I found few question about this but I cannot get it work. I want that everything inside my table is centred vertically and horizontally.

\begin{table}[h!]\centering
    \begin{tabular}{cccccc}
        \hline
        & LH                    & RH                    & \multicolumn{2}{l}{Adjust Phase}              &  \\ \hline
        \multicolumn{1}{l|}{TE11-TE21}      & \multicolumn{1}{l|}{\includegraphics[width=0.15\textwidth]{figure/te1121_lh}} & \multicolumn{1}{l|}{\includegraphics[width=0.15\textwidth]{figure/te1121_rh}} & \multicolumn{1}{l|}{\includegraphics[width=0.15\textwidth]{figure/te1121_corr}} & \multicolumn{1}{l|}{$e^{-j90^\circ}$} &  \\ \hline
        \multicolumn{1}{l|}{HE11-HE21}      & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} &  \\ \hline
        \multicolumn{1}{l|}{TE11-TM01/TE01} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} &  \\ \hline
        \multicolumn{1}{l|}{HE11-TM01/TE01} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & 
    \end{tabular}
    \caption{My caption}
\label{my-label}
\end{table}

An answer here said that m inside multicolumn does the work, but when I try to replace \multicolumn{1}{l|} with \multicolumn{1}{m|} gives me multiple errors. What can I do?

Shika93
  • 371

3 Answers3

2

with use of the macro valign=c from the package adjustbox and with some effort to make table code shoerter:

\documentclass{article}
\usepackage{geometry}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\usepackage{makecell}
\setcellgapes{5pt}

\begin{document}
    \begin{table}[htb]
\centering
\makegapedcells
\setkeys{Gin}{width=\linewidth}
 \begin{tabular}{l|*{3}{p{0.15\textwidth}|}c}
    \hline
            & LH        & RH                & Adjust Phase      &   \\
        \hline
TE11-TE21   & \includegraphics[valign=c]{example-image}    & \includegraphics[valign=c]{example-image}
            & \includegraphics[valign=c]{example-image}       & $e^{-j90^\circ}$  \\  \hline
HE11-HE21       &       &                   &                   &                   \\  \hline
TE11-TM01/TE01  &       &                   &                   &                   \\  \hline
HE11-TM01/TE01  &       &                   &                   &                   \\  \hline
    \end{tabular}
    \caption{My caption}
\label{my-label}
\end{table}
\end{document}

enter image description here

if you rely kike to have contents in all cells horizontally centered, than define table columns as

\begin{tabular}{c|*{3}{p{0.15\textwidth}|}c} % in first column use "c" instead "l"

than you will obtain:

enter image description here

Zarko
  • 296,517
0

You can obtain what you want with a \raisebox{-0.5\height} (approximately):

\documentclass{article}
\usepackage{geometry} 
\usepackage{graphicx} 

\begin{document}

\begin{table}[h!]
\centering
\begin{tabular}{l|*{4}{c|}c}
        \hline
        & LH & RH & \multicolumn{2}{l}{Adjust Phase} & \\ \hline
         TE11-TE21 & \raisebox{-0.46\height}{\includegraphics[width=0.15\textwidth]{femme-araignee}}& \raisebox{-0.46\height}{\includegraphics[width=0.15\textwidth]{femme-araignee}} & \raisebox{-0.46\height}{\includegraphics[width=0.2\textwidth]{snark}} & $e^{-j90^\circ}$ & \\ \hline
        \multicolumn{1}{l|}{HE11-HE21} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \\ \hline
        \multicolumn{1}{l|}{TE11-TM01/TE01} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \\ \hline
        \multicolumn{1}{l|}{HE11-TM01/TE01} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} &
    \end{tabular}
    \caption{My caption}
\label{my-label}
\end{table}

\end{document} 

enter image description here

Bernard
  • 271,350
0

I guess you're using some external utility for making the table, which would explain the wealth of useless \multicolumn commands.

Here are two forms for your table, one jailed and one without vertical rules.

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{booktabs} % for the better table

\newcommand{\vcincludegraphics}[2][]{%
  \includegraphics[#1,valign=c]{#2}%
}

\begin{document}

\begin{table}[htp!]
\centering

\begin{tabular}{|l|c|c|c|c|}
\hline
  & LH
  & RH
  & \multicolumn{2}{c|}{Adjust Phase} \\
\hline
TE11-TE21
  & \vcincludegraphics[width=0.15\textwidth]{example-image}
  & \vcincludegraphics[width=0.15\textwidth]{example-image}
  & \vcincludegraphics[width=0.15\textwidth]{example-image}
  & $e^{-j90^\circ}$ \\
\hline
HE11-HE21      & & & & \\
\hline
TE11-TM01/TE01 & & & & \\
\hline
HE11-TM01/TE01 & & & & \\
\hline
\end{tabular}

\caption{My caption}
\label{my-label}

\end{table}

\begin{table}[htp!]
\centering

\begin{tabular}{@{}lcccc@{}}
\toprule
  & LH
  & RH
  & \multicolumn{2}{c}{Adjust Phase} \\
\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(l){4-5}
TE11-TE21
  & \vcincludegraphics[width=0.15\textwidth]{example-image}
  & \vcincludegraphics[width=0.15\textwidth]{example-image}
  & \vcincludegraphics[width=0.15\textwidth]{example-image}
  & $e^{-j90^\circ}$ \\
\addlinespace
HE11-HE21
  & \vcincludegraphics[width=0.15\textwidth]{example-image}
  & \vcincludegraphics[width=0.15\textwidth]{example-image}
  & \vcincludegraphics[width=0.15\textwidth]{example-image}
  & $e^{-j90^\circ}$ \\
TE11-TM01/TE01 & & & & \\
HE11-TM01/TE01 & & & & \\
\bottomrule
\end{tabular}

\caption{My caption for the better table}
\label{my-label-better}

\end{table}

\end{document}

enter image description here

egreg
  • 1,121,712