表格中上标和下标接触线

表格中上标和下标接触线

我有一张包含数学的表格,上面有下标和上标。它们与表格的上行和下行都相接。我尝试了不少替代方案,但都找不到任何既能在行间留出合适的间距,又不会弄乱标题行的间距(即让标题太紧地左对齐)的方法。如能提供关于最佳方法的任何建议,我将不胜感激。

这是我当前的结果(我正在使用数组包):

在此处输入图片描述

\begin{table}[htbp]
\begin{center}
    \begin{tabular}{| m{2.7cm} | m{8cm}|}
        \hline
        \textbf{Marginalised term} & \textbf{3 variable terms} \\
        \hline \hline 
        $H_\partial^{12}(\{12\})$ & 
        $\begin{aligned} 
            &H_\partial^{123}(\{12\}) + H_\partial^{123}(\{3\}\{12\}) \\
            &+ H_\partial^{123}(\{12\}\{13\}) + H_\partial^{123}(\{12\}\{23\}) \\ 
            &+ H_\partial^{123}(\{12\}\{13\}\{23\})  
            \end{aligned}$ \\
        \hline
        $H_\partial^{12}(\{1\})$ &  
        $H_\partial^{123}(\{1\})+H_\partial^{123}(\{1\}\{23\})+H_\partial^{123}(\{1\}\{3\})$ \\
        \hline
        $H_\partial^{12}(\{2\})$ &  
        $H_\partial^{123}(\{2\})+H_\partial^{123}(\{2\}\{13\})+H_\partial^{123}(\{2\}\{3\})$ \\
        \hline
        $H_\partial^{12}(\{1\}\{2\})$ &  
        $H_\partial^{123}(\{1\}\{2\})+H_\partial^{123}(\{1\}\{2\}\{3\})$ \\
        \hline
  \end{tabular}
\end{center}
\end{table}

设置 extrarowheight 会固定下三行的顶部间距,但它们仍然都接触下部 hline,并且第一行接触上方和下方。

添加extrarowheight不起作用:

在此处输入图片描述

也不arraystrectch(顶行接触和垂直居中):

在此处输入图片描述

答案1

您可以向单元格添加一些垂直填充,方法是使用cellspace,它定义了一个最小在带有以字母 为前缀的说明符的列中,单元格顶部和底部的空白S,或带有makecell,其中添加使用命令在所有单元格的顶部和底部设置固定的垂直间距\makegapedcells

请注意,您不必在段落模式下设置列:第二个代码将列宽设置为其自然宽度。

    \documentclass{article}
    \usepackage{amsmath, array, makecell}
\usepackage{cellspace} %
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}


\begin{document}

\begin{table}[htbp]
\centering
    \begin{tabular}{| S{m{2.7cm}} | Sl|}%{m{8cm}}
        \hline
        \textbf{Marginalised term} & \textbf{3 variable terms} \\
        \hline \hline
        $H_\partial^{12}(\{12\})$ &
        $\begin{aligned}
            &H_\partial^{123}(\{12\}) + H_\partial^{123}(\{3\}\{12\}) \\
            &+ H_\partial^{123}(\{12\}\{13\}) + H_\partial^{123}(\{12\}\{23\}) \\
            &+ H_\partial^{123}(\{12\}\{13\}\{23\})
            \end{aligned}$ \\
        \hline
        $H_\partial^{12}(\{1\})$ &
        $H_\partial^{123}(\{1\})+H_\partial^{123}(\{1\}\{23\})+H_\partial^{123}(\{1\}\{3\})$ \\
        \hline
        $H_\partial^{12}(\{2\})$ &
        $H_\partial^{123}(\{2\})+H_\partial^{123}(\{2\}\{13\})+H_\partial^{123}(\{2\}\{3\})$ \\
        \hline
        $H_\partial^{12}(\{1\}\{2\})$ &
        $H_\partial^{123}(\{1\}\{2\})+H_\partial^{123}(\{1\}\{2\}\{3\})$ \\
        \hline
  \end{tabular}
\end{table}

\begin{table}[htbp]
\centering\setcellgapes{4pt}\makegapedcells \renewcommand\theadfont{\normalsize\bfseries}%
%
 \begin{tabular}{|l| l|}%{m{8cm}}
 \hline
 \thead{Marginalised\\ term} & \thead{3 variable terms} \\
 \hline \hline
 $H_\partial^{12}(\{12\})$ &
 $\begin{aligned}
 &H_\partial^{123}(\{12\}) + H_\partial^{123}(\{3\}\{12\}) \\
 &+ H_\partial^{123}(\{12\}\{13\}) + H_\partial^{123}(\{12\}\{23\}) \\
 &+ H_\partial^{123}(\{12\}\{13\}\{23\})
 \end{aligned}$ \\
 \hline
 $H_\partial^{12}(\{1\})$ &
 $H_\partial^{123}(\{1\})+H_\partial^{123}(\{1\}\{23\})+H_\partial^{123}(\{1\}\{3\})$ \\
 \hline
 $H_\partial^{12}(\{2\})$ &
 $H_\partial^{123}(\{2\})+H_\partial^{123}(\{2\}\{13\})+H_\partial^{123}(\{2\}\{3\})$ \\
 \hline
 $H_\partial^{12}(\{1\}\{2\})$ &
 $H_\partial^{123}(\{1\}\{2\})+H_\partial^{123}(\{1\}\{2\}\{3\})$ \\
 \hline
 \end{tabular}
\end{table}

    \end{document} 

在此处输入图片描述

答案2

可能有更好的方法,但这里我使用了 struts 的组合。我\upstrut在堆栈顶部aligned\downstrut堆栈底部aligned\mystrut简单线条中添加了 。

\documentclass{article}
\usepackage{tabularx,amsmath}
\newcommand\upstrut{\rule{0pt}{12pt}}
\newcommand\downstrut{\rule[-6pt]{0pt}{6pt}}
\newcommand\mystrut{\upstrut\downstrut}
\begin{document}
\begin{table}[htbp]
\begin{center}
    \begin{tabular}{| m{2.7cm} | m{8cm}|}
        \hline
        \textbf{Marginalised term} & \textbf{3 variable terms} \\
        \hline \hline 
        $H_\partial^{12}(\{12\})$ & 
        $\begin{aligned} 
            &\upstrut H_\partial^{123}(\{12\}) + H_\partial^{123}(\{3\}\{12\}) \\
            &+ H_\partial^{123}(\{12\}\{13\}) + H_\partial^{123}(\{12\}\{23\}) \\ 
            &+ H_\partial^{123}(\{12\}\{13\}\{23\}) \downstrut 
            \end{aligned}$ \\
        \hline
        $\mystrut H_\partial^{12}(\{1\})$ &  
        $H_\partial^{123}(\{1\})+H_\partial^{123}(\{1\}\{23\})+H_\partial^{123}(\{1\}\{3\})$ \\
        \hline
        $\mystrut H_\partial^{12}(\{2\})$ &  
        $H_\partial^{123}(\{2\})+H_\partial^{123}(\{2\}\{13\})+H_\partial^{123}(\{2\}\{3\})$ \\
        \hline
        $\mystrut H_\partial^{12}(\{1\}\{2\})$ &  
        $H_\partial^{123}(\{1\}\{2\})+H_\partial^{123}(\{1\}\{2\}\{3\})$ \\
        \hline
  \end{tabular}
\end{center}
\end{table}
\end{document}

在此处输入图片描述

或者,可以\stackgap在每行的术语中添加一个,从而在3pt该术语的上方和下方添加一个(默认)缓冲区。可选参数可以更改堆栈间隙值:

\documentclass{article}
\usepackage{tabularx,amsmath,stackengine}
\begin{document}
\begin{table}[htbp]
\begin{center}
    \begin{tabular}{| m{2.7cm} | m{8cm}|}
        \hline
        \textbf{Marginalised term} & \textbf{3 variable terms} \\
        \hline \hline 
        $H_\partial^{12}(\{12\})$ & 
        \addstackgap{$\begin{aligned} 
            &H_\partial^{123}(\{12\}) + H_\partial^{123}(\{3\}\{12\}) \\
            &+ H_\partial^{123}(\{12\}\{13\}) + H_\partial^{123}(\{12\}\{23\}) \\ 
            &+ H_\partial^{123}(\{12\}\{13\}\{23\}) 
            \end{aligned}$} \\
        \hline
        \addstackgap{$H_\partial^{12}(\{1\})$} &  
        $H_\partial^{123}(\{1\})+H_\partial^{123}(\{1\}\{23\})+H_\partial^{123}(\{1\}\{3\})$ \\
        \hline
        \addstackgap{$H_\partial^{12}(\{2\})$} &  
        $H_\partial^{123}(\{2\})+H_\partial^{123}(\{2\}\{13\})+H_\partial^{123}(\{2\}\{3\})$ \\
        \hline
        \addstackgap{$H_\partial^{12}(\{1\}\{2\})$} &  
        $H_\partial^{123}(\{1\}\{2\})+H_\partial^{123}(\{1\}\{2\}\{3\})$ \\
        \hline
  \end{tabular}
\end{center}
\end{table}
\end{document}

在此处输入图片描述

答案3

排版此表格最吸引人的方式是不使用任何垂直线,而是使用数量少但间距合适的水平线。这样一来,下标和上标术语接触水平线的问题就不会出现。而且,无需费心摆弄\arraystretch

由于表格中几乎所有内容都是数学内容,我建议使用环境array而不是tabular环境。如果没有其他选择,您可以省去输入大量$符号的麻烦。

另外,由于H_\partial在表中出现了大约 17 次,我建议您将所有实例替换为\Hp,其中\Hp在序言中定义为,您猜对了,H_\partial

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,booktabs,array}
\newcommand{\Hp}{H_\partial} % shortcut macro
\begin{document}
\begin{table}[htbp]
\centering

$\begin{array}{@{}ll@{}}
    \toprule
    \multicolumn{1}{@{}m{2.7cm}}{\textbf{Marginalised term}} & 
    \textbf{3 variable terms} \\
    \midrule
    \Hp^{12}(\{12\}) & 
    \!\begin{aligned}[t]
      &\Hp^{123}(\{12\}) + \Hp^{123}(\{3\}\{12\}) \\
      &\quad+ \Hp^{123}(\{12\}\{13\}) + \Hp^{123}(\{12\}\{23\}) \\ 
      &\quad+ \Hp^{123}(\{12\}\{13\}\{23\})  
    \end{aligned} \\
    \addlinespace
    \Hp^{12}(\{1\}) &  
    \Hp^{123}(\{1\})+\Hp^{123}(\{1\}\{23\})+\Hp^{123}(\{1\}\{3\}) \\
    \addlinespace
    \Hp^{12}(\{2\}) &  
    \Hp^{123}(\{2\})+\Hp^{123}(\{2\}\{13\})+\Hp^{123}(\{2\}\{3\}) \\
    \addlinespace
    \Hp^{12}(\{1\}\{2\}) &  
    \Hp^{123}(\{1\}\{2\})+\Hp^{123}(\{1\}\{2\}\{3\}) \\
    \bottomrule
\end{array}$

\end{table}
\end{document}

相关内容