LyX 表内的数学模式

LyX 表内的数学模式

如果我在表格单元格内插入数学模式环境,那么输出将显示边框和公式之间没有垂直空间,这里有一个示例:

在此处输入图片描述

有没有什么方法可以让边框从公式中获得更多垂直空间?

答案1

可以使用普通的 TeX/LaTeX 处理来构建一个相当简单的解决方法boxes;由于 LaTeX 的单元格垂直空间不考虑命令\displaystyle,一种解决方案是通过将方程式插入到parbox环境:

\parbox[⟨alignment⟩][⟨height⟩][⟨arrangement⟩]{⟨width⟩}{⟨contents⟩} 

首先,将alignmentarrangement参数设置为居中(c);有趣的维度参数是heightwidth:由于方程将存储其特定的高度(基线以上)、深度(基线以下)和宽度,因此可以使用以下方式轻松在 parbox 的可选/强制参数中替换这些维度calc的命令:

total height: \totalheightof{⟨content⟩}+2\fboxsep+2\fboxrule  (pt)
total width : \widthof{⟨content⟩}                             (pt)

注意到此设置可以应用于两个都框内的任何文本或数学运算,\mytabspace{⟨your equation⟩}都可以创建一个有用的宏,其定义为:

% implementing more dimension/expression handling control sequences
\usepackage{calc}
%
\newcommand\mytabspace[1]{%
 \parbox[c][\totalheightof{#1}+2\fboxsep+2\fboxrule][c]{\widthof{#1}}{#1}%
}

另一个等效的解决方案是将子单元格的内容存储在一个临时的框中\@tempboxa;因此不必担心在文档内部重复实现,因为如果框尺寸是在组内定义的,则一旦超出命令范围,它们就会重置为新的框内容:

\makeatletter
\newcommand\mytabspace[1]{% 
 \sbox\@tempboxa{#1}%
 \parbox[c][\ht\@tempboxa+\dp\@tempboxa+2\fboxsep+2\fboxrule][c]{\wd\@tempboxa}{%
  \usebox\@tempboxa%
 }%
}
\makeatother

通过简单的 MWE 看到它的实际作用,背后的所有工作都得到了回报:

\documentclass{article}
%
\usepackage{calc}
%
\newcommand\mytabspace[1]{%
 \parbox[c][\totalheightof{#1}+2\fboxsep+2\fboxrule][c]{\widthof{#1}}{#1}%
}
% comment out the lines below and comment the beforementioned command,
% you'll see that the output is the same.
%\makeatletter
%\newcommand\mytabspace[1]{% 
% \sbox\@tempboxa{#1}%
% \parbox[c][\ht\@tempboxa+\dp\@tempboxa+2\fboxsep+2\fboxrule][c]{\wd\@tempboxa}{%
%  \usebox\@tempboxa%
% }%
%}
%\makeatother
%
\begin{document}
%
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|}
\hline
Function   & Integral   \\
\hline
$-$  & This is not my macro: a   \\
\hline
% test if there are unwanted vertical space additions
$-$  & This is my macro: \mytabspace{a}  \\
\hline
% now the integral becomes:
$\sin(x)$  & \mytabspace{$\displaystyle{\lim_{n\to+\infty}\sum_{k=1}^n\sin(c_k)\Delta x_k=\int_a^b\sin(x)\,\mathrm{d}x}$}   \\
\hline
\end{tabular}
\caption{This is a spaced equation, finally at last!}
\end{table}
%
\end{document}

通过所示的输出,可以观察mytabspace对任何垂直间距进行修改,以证明其多功能性:

在此处输入图片描述

继续使用 LyX,访问菜单,可以粘贴显示的Document → Settings → LaTeX preamble任何宏\mytabspace定义;因为程序本身会自动添加\makeatletter\makeatother放在白色序言中(第二个代码应该不是用这两个命令粘贴,它们会变得多余)。

此时,所需的数学环境可以通过简单的 ERT 来界定:

在此处输入图片描述

给出最终的预期输出:

在此处输入图片描述

此外,我要感谢@DavidCarlisle 提供的有用提示(但仅限于第二个代码=P);更重要的是:

我在刚开始使用 LyX 时也遇到过这个问题(例如,当时我甚至不知道“控制序列”是什么意思);但我能够面对它现在。

相关内容