表格单元格的垂直间距

表格单元格的垂直间距

我想将公式制成表格,但我发现表格单元格的线条太近,这在审美上不令人满意。示例(公式复制自维基百科):

\begin{tabular}{|c|c|}
\hline
Cylindrical & $\displaystyle{{1 \over \rho}{\partial \over \partial\rho}\left(\rho {\partial f \over \partial \rho}\right)
+ {1 \over \rho^2}{\partial^2 f \over \partial \phi^2}  + {\partial^2 f \over \partial z^2}}$\\\hline
Spherical & $\displaystyle{{1 \over r^2}{\partial \over \partial r}\!\left(r^2 {\partial f \over \partial r}\right)
\!+\!{1 \over r^2\!\sin\theta}{\partial \over \partial \theta}\!\left(\sin\theta {\partial f \over \partial \theta}\right)
\!+\!{1 \over r^2\!\sin^2\theta}{\partial^2 f \over \partial \phi^2}}$\\\hline
\end{tabular}

给出了

表输出

你会看到公式的顶部被线条切断了。有什么建议吗?

答案1

我过去曾通过修改\arraystretch

您可以通过添加到您的源来做到这一点:

{\renewcommand{\arraystretch}{1.2} %<- modify value to suit your needs
\begin{tabular}{|c|c|}
...
\end{tabular}
}

编辑:

实际上,经过更多的研究,似乎在单元格中存在方程式会出现意外行为,其中顶部的空间不成比例地增加(将值设置为 3 以开始获取底部的空间):

表格的 arraystretch 设置为 3

最近我开始使用该tabu包替换所有表格(从tabulartabularxlongtable)。它还提供了一些其他控件。在这种情况下,\tabulinesep对结果的影响更为恰当:

\documentclass[preview]{standalone}
   \usepackage{tabu}
   \begin{document}
   {\tabulinesep=1.2mm
   \begin{tabu} {|c|c|}
       \hline
       Cylindrical & $\displaystyle{{1 \over \rho}{\partial \over \partial\rho}\left(\rho {\partial f \over \partial \rho}\right)
       + {1 \over \rho^2}{\partial^2 f \over \partial \phi^2}  + {\partial^2 f \over \partial z^2}}$\\\hline
       Spherical & $\displaystyle{{1 \over r^2}{\partial \over \partial r}\!\left(r^2 {\partial f \over \partial r}\right)
       \!+\!{1 \over r^2\!\sin\theta}{\partial \over \partial \theta}\!\left(\sin\theta {\partial f \over \partial \theta}\right)
       \!+\!{1 \over r^2\!\sin^2\theta}{\partial^2 f \over \partial \phi^2}}$\\\hline
   \end{tabu}}
\end{document}

其结果如下:

tabu 将 tabulinesep 设置为 1.2mm

答案2

您可以使用不同的表格格式,省略不必要的垂直线;您还可以使用个人偏导数命令大大简化输入:

\documentclass{article}

\usepackage{booktabs,amsmath}

\newcommand{\dpder}[3][]{\dfrac{\partial^{#1}#2}{\partial #3}}

\begin{document}
\begin{tabular}{lc}
\toprule
Cartesian &
$\dpder[2]{f}{x^2}+\dpder[2]{f}{y^2}+\dpder[2]{f}{z^2}$
\\
\midrule
Cylindrical &
$\dfrac{1}{\rho} \dpder{}{\rho}{\left(\rho \dpder{f}{\rho}\right)}
  + \dfrac{1}{\rho^2} \dpder[2]{f}{\phi^2} + \dpder[2]{f}{z^2}$
\\
\midrule
Spherical &
$\dfrac{1}{r^2}\dpder{}{r}{\left(r^2 \dpder{f}{r}\right)}
  +\dfrac{1}{r^2\sin\theta}\dpder{}{\theta}{\left(\sin\theta \dpder{f}{\theta}\right)}
  +\dfrac{1}{r^2\sin^2\theta}\dpder[2]{f}{\phi^2}$
\\
\bottomrule
\end{tabular}
\end{document}

请注意如何使用{\left(...\right)}(一对括号就足够了,而不需要显式备份)来避免“圆柱”和“球形”行中不必要的空格。还请注意\dfrac在定义中的使用\dpder,这避免了指定\displaystyle(然而不是一个接受参数的命令,但是一个声明)。

由于booktabs很少需要调整行距。

在此处输入图片描述

答案3

作为过时软件包的替代方案tabu,新的tabularray软件包rowsep为表格提供了选项:

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{tblr}{|c|c|}
\hline
Cylindrical & $\displaystyle{{1 \over \rho}{\partial \over \partial\rho}\left(\rho {\partial f \over \partial \rho}\right)
+ {1 \over \rho^2}{\partial^2 f \over \partial \phi^2}  + {\partial^2 f \over \partial z^2}}$\\\hline
Spherical & $\displaystyle{{1 \over r^2}{\partial \over \partial r}\!\left(r^2 {\partial f \over \partial r}\right)
\!+\!{1 \over r^2\!\sin\theta}{\partial \over \partial \theta}\!\left(\sin\theta {\partial f \over \partial \theta}\right)
\!+\!{1 \over r^2\!\sin^2\theta}{\partial^2 f \over \partial \phi^2}}$\\\hline
\end{tblr}

\bigskip

\SetTblrInner{rowsep=4pt}

\begin{tblr}{|c|c|}
\hline
Cylindrical & $\displaystyle{{1 \over \rho}{\partial \over \partial\rho}\left(\rho {\partial f \over \partial \rho}\right)
+ {1 \over \rho^2}{\partial^2 f \over \partial \phi^2}  + {\partial^2 f \over \partial z^2}}$\\\hline
Spherical & $\displaystyle{{1 \over r^2}{\partial \over \partial r}\!\left(r^2 {\partial f \over \partial r}\right)
\!+\!{1 \over r^2\!\sin\theta}{\partial \over \partial \theta}\!\left(\sin\theta {\partial f \over \partial \theta}\right)
\!+\!{1 \over r^2\!\sin^2\theta}{\partial^2 f \over \partial \phi^2}}$\\\hline
\end{tblr}

\end{document}

在此处输入图片描述

答案4

有了,您可以使用和{NiceTabular},但您也有一个密钥。nicematrix\arraystretch\extrarowheightarraycell-space-limits

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
\begin{NiceTabular}{cc}[hvlines,cell-space-limits=3pt]
Cylindrical & $\displaystyle{{1 \over \rho}{\partial \over \partial\rho}\left(\rho {\partial f \over \partial \rho}\right)
+ {1 \over \rho^2}{\partial^2 f \over \partial \phi^2}  + {\partial^2 f \over \partial z^2}}$\\
Spherical & $\displaystyle{{1 \over r^2}{\partial \over \partial r}\!\left(r^2 {\partial f \over \partial r}\right)
\!+\!{1 \over r^2\!\sin\theta}{\partial \over \partial \theta}\!\left(\sin\theta {\partial f \over \partial \theta}\right)
\!+\!{1 \over r^2\!\sin^2\theta}{\partial^2 f \over \partial \phi^2}}$\\
\end{NiceTabular}
\end{document}

上述代码的输出

相关内容