如何将图像放入 tabularx booktabs 表中而不移动同一行中的文本,并将其垂直对齐到中心?

如何将图像放入 tabularx booktabs 表中而不移动同一行中的文本,并将其垂直对齐到中心?

如果这很容易,我很抱歉,但我被这个问题难住了,我已经浏览了许多其他答案,但这些答案对我没有帮助。我尝试使用 raisebox,它对我有点帮助。但是 raisebox 和 valign 也没有帮助我。我将使用 raisebox 命令发布当前代码,因为它看起来是所有选项中最好的。我将发布我从另一篇文章中获得的我自己的列类型,我在文档中使用了它。我无法发布完整的文档,因为它太长了。我也想在每一行中使用数字,但我只能使用第一个。

我基本上是想让图像在行内垂直和水平居中,并且不在同一行的文本上方创建空白。

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{table}[htbp] \centering
\begin{tabularx}{\textwidth}{YYXX}
\toprule
Parameter & Unit & Description & Figure \\ 
\toprule
Infill Density & \% & Density of the infill structure. Ranges from zero percent (hollow part) to one hundred percent (solid part)  & \raisebox{-.5\height}{\includegraphics[width=0.9\linewidth]{/graphics/veranschaulichung/infill}} \\ 
\midrule
Infill Structure & - & Geometry of the infill structure & \\ 
\midrule
Shell/Wall Thickness & mm & Thickness of vertical walls & \\ 
\midrule
Layer Height & mm & Controls the distance of the nozzle to the previous layer/build platform & \\ 
\midrule
Nozzle Temperature & °C & Temperature used to melt the material & \\ 
\bottomrule
\end{tabularx}
\caption{Important parameters influencing the mechanical properties of additively manufactured components}
\label{table_addparam}
\end{table}

我的图形移动了文本并创建了一个空白空间。

答案1

尝试一下这个代码。

它重新定义\tabularxcolumn为制作一个垂直居中的X列。它还将单元格水平居中。

A

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage[left=2.00cm, right=2.00cm, top=4.00cm, bottom=3.00cm]{geometry}

\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\usepackage{booktabs}

\begin{document}        
    
    \begin{table}[htbp] 
        \renewcommand\tabularxcolumn[1]{m{#1}}% added <<<<<<<<<<<<<<
        \centering
        \begin{tabularx}{\textwidth}{YY X >{\centering\arraybackslash}X@{}}% changed <<<<<<<<<<<
            \toprule
            Parameter & Unit & Description & Figure \\ 
            \toprule
            Infill Density & \% & Density of the infill structure. Ranges from zero percent (hollow part) to one hundred percent (solid part)  & \includegraphics[width=0.9\linewidth]{example-image-a} \\ 
            \midrule
            Infill Structure & - & Geometry of the infill structure & \\ 
            \midrule
            Shell/Wall Thickness & mm & Thickness of vertical walls & \\ 
            \midrule
            Layer Height & mm & Controls the distance of the nozzle to the previous layer/build platform &\includegraphics[width=0.7\linewidth]{example-image-b} \\         
            \midrule
            Nozzle Temperature & °C & Temperature used to melt the material & \\ 
            \bottomrule
        \end{tabularx}
        \caption{Important parameters influencing the mechanical properties of additively manufactured components}
        \label{table_addparam}
    \end{table}
\end{document}

答案2

我不会使用垂直居中。但是如果你愿意,可以使用\tabularxcolumn第一个表格的方法。

无论哪种情况,我都会扩大第三列,而其他三列则保持其自然大小,以免出现过大的空白,并将大部分保留给长文本。

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{tabularx}

\usepackage{booktabs}

\begin{document}        
    
\begin{table}[!htbp] 
\centering

\renewcommand{\tabularxcolumn}[1]{m{#1}} % vertical centering

\begin{tabularx}{\textwidth}{@{}lcXc@{}}
\toprule
Parameter & Unit & \multicolumn{1}{c}{Description} & Figure \\ 
\toprule
Infill Density & \% &
  Density of the infill structure. Ranges from zero percent (hollow part) 
  to one hundred percent (solid part)  &
  \includegraphics[width=0.125\columnwidth,valign=c]{example-image-a} \\ 
\midrule
Infill Structure & -- & Geometry of the infill structure & \\ 
\midrule
Shell/Wall Thickness & mm & Thickness of vertical walls & \\ 
\midrule
Layer Height & mm &
  Controls the distance of the nozzle to the previous layer/build platform &
  \includegraphics[width=0.125\columnwidth,valign=c]{example-image-b} \\         
\midrule
Nozzle Temperature & °C & Temperature used to melt the material & \\ 
\bottomrule
\end{tabularx}

\caption{Important parameters influencing the mechanical properties of 
  additively manufactured components}
\label{table_addparam}
\end{table}

\begin{table}[!htbp] 
\centering

\begin{tabularx}{\textwidth}{@{}lcXc@{}}
\toprule
Parameter & Unit & \multicolumn{1}{c}{Description} & Figure \\ 
\toprule
Infill Density & \% &
  Density of the infill structure. Ranges from zero percent (hollow part) 
  to one hundred percent (solid part)  &
  \includegraphics[width=0.125\columnwidth,valign=t]{example-image-a} \\ 
\midrule
Infill Structure & -- & Geometry of the infill structure & \\ 
\midrule
Shell/Wall Thickness & mm & Thickness of vertical walls & \\ 
\midrule
Layer Height & mm &
  Controls the distance of the nozzle to the previous layer/build platform &
  \includegraphics[width=0.125\columnwidth,valign=t]{example-image-b} \\         
\midrule
Nozzle Temperature & °C & Temperature used to melt the material & \\ 
\bottomrule
\end{tabularx}

\caption{Important parameters influencing the mechanical properties of 
  additively manufactured components}
\label{table_addparam2}
\end{table}

\end{document}

在此处输入图片描述

答案3

您仍然可以使用顶部对齐的列和中间对齐的图像\raisebox,但您需要预先计算要对齐的文本的高度和深度。

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage[left=2.00cm, right=2.00cm, top=4.00cm, bottom=3.00cm]{geometry}

\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\usepackage{booktabs}

\begin{document}        
    
\begin{table}[htbp] \centering
\setlength{\dimen0}{\dimexpr 0.25\textwidth-2\tabcolsep}% width of X column
\sbox0{\parbox[t]{\dimen0}{Density of the infill structure. Ranges from zero percent (hollow part) to one hundred percent (solid part)}}% measure

\begin{tabularx}{\textwidth}{YYXX}
\toprule
Parameter & Unit & Description & Figure \\ 
\toprule
Infill Density & \% & \usebox0 & \hfil\raisebox{\dimexpr 0.5\ht0-0.5\dp0-0.5\height}%
  {\includegraphics[width=0.9\linewidth]{example-image}} \\ 
\midrule
Infill Structure & - & Geometry of the infill structure & \\ 
\midrule
Shell/Wall Thickness & mm & Thickness of vertical walls & \\ 
\midrule
Layer Height & mm & Controls the distance of the nozzle to the previous layer/build platform & \\ 
\midrule
Nozzle Temperature & °C & Temperature used to melt the material & \\ 
\bottomrule
\end{tabularx}
\caption{Important parameters influencing the mechanical properties of additively manufactured components}
\label{table_addparam}
\end{table}

\end{document}

相关内容