我找到了一些关于此的问题,但我无法让它工作。我希望表格中的所有内容都垂直和水平居中。
\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}
这里的答案说m
insidemulticolumn
可以工作,但是当我尝试\multicolumn{1}{l|}
用替换时\multicolumn{1}{m|}
,会出现多个错误。我该怎么办?
答案1
使用valign=c
包中的宏adjustbox
并稍加努力使表代码更简洁:
\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}
如果你依赖 kike 将所有单元格中的内容水平居中,那么将表格列定义为
\begin{tabular}{c|*{3}{p{0.15\textwidth}|}c} % in first column use "c" instead "l"
你将获得:
答案2
你可以通过(大约)获得你想要的东西\raisebox{-0.5\height}
:
\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}
答案3
我猜你正在使用一些外部实用程序来制作表格,这可以解释大量无用的\multicolumn
命令。
这里有两张表格,一张有垂直线,一张没有。
\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}