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?

  • The m column specifier (as well as p or b) is for columns in paragraph mode, ans it requires an argument – the column width. – Bernard Jun 26 '18 at 9:42
  • Here [tex.stackexchange.com/questions/113022/… used \multicolumn{1}{|m{\tempwidth}|} but give me error as well – Shika93 Jun 26 '18 at 9:51
  • If you want everything to be vertically and horizontally centered, why do you use \multicolumn{1}{l|} commands? Also, why do you specify 6 columns, as you only seem to use 5 of them? – leandriis Jun 26 '18 at 11:43
  • For further information on the alignment of images, you might also want to have a look here: How to vertically center text with an image in the same row of a table – leandriis Jun 26 '18 at 11:48
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

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

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

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.