表格:将单元格内容对齐到左上角(包括图像)

表格:将单元格内容对齐到左上角(包括图像)

我在对齐表格左上角单元格内容时遇到了麻烦。问题似乎是由 SVG 文件引起的,因为没有它一切都运行正常。此外,一旦我引入makecell垂直对齐,自动换行似乎也会横向移动。

坏桌子

最小工作示例:

\documentclass[11pt, a4paper, oneside, titlepage]{extarticle}

\usepackage[top=3cm, bottom=3cm, left=3cm, right=3cm]{geometry} 
\usepackage[sfdefault]{carlito}
\usepackage{svg}
\usepackage{makecell}

\begin{document}

\begin{table}
  \begin{center}
    \begin{tabular*}{16cm}{p{3cm} p{4cm} p{9cm}}
      \hline
      \makecell[tl]{\includesvg[width=2.5cm]{assets/ERROR_Battery.svg}} & \makecell[tl]{\textbf{Battery Error}} & \makecell[tl]{This error code indicates that there is a problem with the battery and/or the charging electronics.}\\
      \hline
      \makecell[tl]{img here} & \makecell[tl]{\textbf{GNSS Error}} & \makecell[tl]{This error code indicates that there is a problem communicating with the GNSS module.}\\
      \hline
      \makecell[tl]{img here} & \makecell[tl]{\textbf{IMU Error}} & \makecell[tl]{This error code indicates that there is a problem communicating with either one or both of the inertial measurement units.}\\
      \hline
      \makecell[tl]{img here} & \makecell[tl]{\textbf{WiFi Error}} & \makecell[tl]{This error code indicates that there is a problem communicating with the WiFi module.}\\
      \hline
      \makecell[tl]{img here} & \makecell[tl]{\textbf{Internal Storage Error}} & \makecell[tl]{This error code indicates that there is a problem reading the internal memory.}\\
    \end{tabular*}
  \end{center}
\end{table}

\end{document}

也许有人能给我一些提示,告诉我如何实现我的需求。谢谢!

答案1

您需要将图像基线移至其顶部。adjustbox当图像包含在以下包中时,可以使用以下方法轻松完成此操作\includegraphics

在此处输入图片描述

\documentclass[11pt, a4paper, oneside, titlepage]{extarticle}
\usepackage[margin=3cm]{geometry}   % shortened
\usepackage[sfdefault]{carlito}
\usepackage{svg}
\usepackage[export]{adjustbox}  % for "valign",  also load graphicx
\usepackage{booktabs, tabularx}

\begin{document}

    \begin{table}[!ht]
\centering 
\setkeys{Gin}{width=\linewidth}
\begin{tabularx}{\linewidth}{p{25mm} >{\bfseries}l X}
      \toprule
\includegraphics[valign=t]{example-image-duck}
    & Battery Error &   This error code indicates that there is
                        a problem with the battery and/or the charging electronics. \\
                        
      \midrule
\includegraphics[valign=t]{example-image-duck}
    & GNSS Error    &   This error code indicates that there is
                        a problem communicating with the GNSS module.               \\
      \midrule
\includegraphics[valign=t]{example-image-duck}
    & Error         &   This error code indicates that there is
                        a problem communicating with either one or both of the inertial measurement units.                                          \\
      \midrule
\includegraphics[valign=t]{example-image-duck}
    & WiFi Error    &   This error code indicates that there is
                        a problem communicating with the WiFi module.               \\
      \midrule
\includegraphics[valign=t]{example-image-duck}
    & Internal Storage Error
                &   This error code indicates that there is
                    a problem reading the internal memory.                          \\
    \bottomrule
\end{tabularx}
    \end{table}

\end{document}

但是,我会将\midrule表体中的所有 s 替换为\addlinespace

在此处输入图片描述

不幸的是,此解决方案不适用于包\includesvg的命令svg。我希望将.svg图像转换为.pdf不会给您带来太多麻烦。

相关内容