解释 \begin{tabularx}{*} 命令以对齐表格中的文本和图像

解释 \begin{tabularx}{*} 命令以对齐表格中的文本和图像

我正在尝试在表格中垂直对齐文本和图片。我看过几个解决这个问题的提要,但我仍然不明白如何\tabularx{}{}命令的使用和含义。特别是括号的第二部分,您指定m{},p{},b{}ETC。

就我而言,我已经使用了{\textwidth}{c*{2}{Y}}- 从另一个发布的答案中得到这个 - 不确定它到底是什么意思......

附件是我正在创建的表的代码和图像:

\begin{table}[H]
 \caption{Classification}
 \label{tbl:Longwall systems}
 \footnotesize
 \centering 

    \begin{tabularx}{\textwidth}{c *{2}{Y}}
     \toprule 
      Classifications & Description \\ 
     \midrule
     \raisebox{-\totalheight}{\includegraphics[width=0.3\textwidth, height=30mm]{./Figures/Longwall single entry retreating}} & Single entry advancing\\
      \midrule

      {\includegraphics[width=0.3\textwidth, height=30mm]{./Figures/Longwall single entry retreating}} & Single entry retreating\\
      \midrule
      \end{tabularx}

\end{table}               

我只是想将文本和图像垂直对齐到表格的中心。

非常感谢您的帮助。谢谢(请注意,我对乳胶还不熟悉:)) 在此处输入图片描述

答案1

由于不知道Y列类型是什么,我将其替换为X。您可以使用 或使用选项\raisebox{-0.5\totalheight}{…}加载包 并使用。 adjustboxexport\includegraphics[valign=c]

\documentclass{article}
\usepackage[demo, export]{adjustbox}
\usepackage{float, tabularx, booktabs, caption}

\begin{document}

\setcounter{table}{4}
\begin{table}[H]
 \caption{Classification}
 \label{tbl:Longwall systems}
 \footnotesize
 \centering

    \begin{tabularx}{\textwidth}{c *{2}{X}}
     \toprule
      Classifications & Description \\
     \midrule
     \raisebox{-0.5\totalheight}{\includegraphics[width=0.3\textwidth, height=30mm]{./Figures/Longwall single entry retreating}} & Single entry advancing\\
      \midrule

      {\includegraphics[width=0.3\textwidth, height=30mm, valign=c]{./Figures/Longwall single entry retreating}} & Single entry retreating\\
      \midrule
      \end{tabularx}

\end{table}

\end{document} 

在此处输入图片描述

答案2

在此处输入图片描述

 \documentclass{article}
% \usepackage[flushleft]{threeparttable}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
            \begin{table}
 \caption{Classification}
 \label{tbl:Longwall systems}
 \footnotesize
 \centering 

    \begin{tabular}{m{0.4\linewidth}m{0.5\linewidth}}
     \toprule 
      Classifications & Description \\ 
     \midrule
     {\includegraphics[width=0.3\textwidth, height=30mm]{example-image}} & Single entry advancing\\
      \midrule
      {\includegraphics[width=0.3\textwidth, height=30mm]{example-image}} & Single entry retreating\\
      \midrule
      \end{tabular}

\end{table}   
\end{document}

编辑 将标题居中——以前没有这样做过

在此处输入图片描述

\begin{tabular}{>{\centering\arraybackslash}m{2in}>{\centering\arraybackslash}m{4in}}
 \toprule 
  Classifications & Description \\ 
 \midrule
 {\includegraphics[width=0.3\textwidth]{example-image}} & Single entry advancing\\
  \midrule
  {\includegraphics[width=0.3\textwidth]{example-image}} & Single entry retreating\\
  \midrule
  \end{tabular}

相关内容