tabularx 中单元格内容的顶部对齐

tabularx 中单元格内容的顶部对齐

我想将每个单元格(第一列)的内容与顶部对齐。所介绍的方法这里tabular不适用。也许它与环境中的死环境有关tabularx

看起来怎么样

i1

我希望它看起来像什么

i2

平均能量损失

\documentclass{article}
\usepackage{tabularx,booktabs} 

\begin{document}

    \begin{tabularx}{\textwidth}{lX}
        \toprule
        Mittel    & technische Details\\
        \midrule
        %first row of tabularx
        Laptop      &
            \begin{tabular}{ll}
            MacBook Pro & \\
            Baujahr 2010 & \\ 
            Prozessor & 2.4 GHz Intel Core 2 Duo \\
            Speicher & 4 GB 1067 MHz DDR3 \\
            Software & Mac OS X Lion 10.7.5 (11G63)
            \end{tabular}\\[3em]
        %second row of tabularx
        Programmierumgebung          &
            \begin{tabular}{ll}
            Version & 8.0.4.0 \\
            Plattform & Mac OS x86 (32-bit, 64-bit Kernel)
            \end{tabular}\\
        \bottomrule
    \end{tabularx}

\end{document}

答案1

在此处输入图片描述

您可以使用它使内部表格顶部对齐,[t]这可能只是您的小示例的产物,但 tabularx 在这里无法提供任何帮助,因为内部表格固定为其自然宽度,因此无法重新流动到列X指定的任何宽度。

\documentclass{article}
\usepackage{tabularx,booktabs} 

\begin{document}
\noindent
    \begin{tabularx}{\textwidth}{lX}
        \toprule
        Mittel    & technische Details\\
        \midrule
        %first row of tabularx
        Laptop      &
            \begin{tabular}[t]{ll}
            MacBook Pro & \\
            Baujahr 2010 & \\ 
            Prozessor & 2.4 GHz Intel Core 2 Duo \\
            Speicher & 4 GB 1067 MHz DDR3 \\
            Software & Mac OS X Lion 10.7.5 (11G63)
            \end{tabular}\\[3em]
        %second row of tabularx
        Programmierumgebung          &
            \begin{tabular}[t]{ll}
            Version & 8.0.4.0 \\
            Plattform & Mac OS x86 (32-bit, 64-bit Kernel)
            \end{tabular}\\
        \bottomrule
    \end{tabularx}

\end{document}

答案2

为什么不使用单一tabularx环境,而是使用内部环境tabular

\begin{tabularx}{\textwidth}{llX}
    \toprule
    Mittel              & technische Details & \\
    \midrule
    Laptop              & MacBook Pro  & \\
                        & Baujahr 2010 & \\ 
                        & Prozessor    & 2.4 GHz Intel Core 2 Duo \\
                        & Speicher     & 4 GB 1067 MHz DDR3 \\
                        & Software     & Mac OS X Lion 10.7.5 (11G63) \\[3em]
    Programmierumgebung & Version      & 8.0.4.0 \\
                        & Plattform    & Mac OS x86 (32-bit, 64-bit Kernel)\\
    \bottomrule
\end{tabularx}

示例输出

答案3

可以tabular通过可选参数指定环境的垂直对齐方式——顶部、中间(默认)和底部。在下面的代码中,我使用[t](表示“顶部”对齐)。请注意,现在还需要通过指令明确抑制空格,否则当使用包含环境的单元格的列类型@{}时,这些空格会插入到单元格的左边缘。Xtabular

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,booktabs} 
\begin{document}
\noindent
  \begin{tabularx}{\textwidth}{lX}
    \toprule
    Mittel  & technische Details\\
    \midrule
    %first row of tabularx
    Laptop    &
      \begin{tabular}[t]{@{}ll} 
         % use [t] alignment specifier, and @{} to 
         % suppress extra whitespace at left edge
      MacBook Pro & \\
      Baujahr 2010 & \\ 
      Prozessor & 2.4 GHz Intel Core 2 Duo \\
      Speicher & 4 GB 1067 MHz DDR3 \\
      Software & Mac OS X Lion 10.7.5 (11G63)
      \end{tabular}\\[5em]
    %second row of tabularx
    Programmierumgebung      &
      \begin{tabular}[t]{@{}ll} 
      Version & 8.0.4.0 \\
      Plattform & Mac OS x86 (32-bit, 64-bit Kernel)
      \end{tabular}\\
    \bottomrule
  \end{tabularx}
\end{document}

相关内容