我定义了一个带有 3 个参数的新命令\nonBranchingRule
。直观地说,它定义了一个规则,其中最后一个参数是该规则的注释(可选参数)。我想将注释放在规则下方,并将两者居中。我使用表格来实现这一点。我添加了表格行来测试规则和注释的实际排列。
MWE 如下:
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\newcommand{\nonBranchingRule}[3][]{
\begin{tabular}{|c|}
$\dfrac{
\begin{tabular}{c}
#2
\end{tabular}}
{
\raisebox{-4pt}{
\begin{tabular}[t]{c}
#3
\end{tabular}}
}$#1
\end{tabular}}
\begin{document}
\nonBranchingRule{$H$}
{$G$}
{\\$G$ and $H$ are terms}
\vspace{2cm}
\begin{tabular}{|c|}
$\dfrac{
\begin{tabular}{c}
$H$
\end{tabular}
}
{
\raisebox{-4pt}{
\begin{tabular}[t]{c}
$G$
\end{tabular}}
}$\\$G$ and $H$ are terms
\end{tabular}
\end{document}
我希望得到第二种情况,但\nonBranchingRule
我得到的是第一种情况。
答案1
您的#1
#2
#3` 顺序错误,并且可选参数未使用。
这里我展示了两种\nonBranchingRule
具有三个强制参数的形式,
\nonBranchingRuleB
其中规则参数是首先给出的可选参数[]
。
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\newcommand{\nonBranchingRule}[3]{
\begin{tabular}{|c|}
$\dfrac{
\begin{tabular}{c}
#1
\end{tabular}}
{
\raisebox{-4pt}{
\begin{tabular}[t]{c}
#2
\end{tabular}}
}$#3
\end{tabular}}
\newcommand{\nonBranchingRuleB}[3][]{
\begin{tabular}{|c|}
$\dfrac{
\begin{tabular}{c}
#2
\end{tabular}}
{
\raisebox{-4pt}{
\begin{tabular}[t]{c}
#3
\end{tabular}}
}$#1
\end{tabular}}
\begin{document}
\nonBranchingRule{$H$}
{$G$}
{\\$G$ and $H$ are terms}
\vspace{2cm}
\nonBranchingRuleB
{$H$}
{$G$}
\vspace{2cm}
\nonBranchingRuleB
[\\$G$ and $H$ are terms]
{$H$}
{$G$}
\vspace{2cm}
\begin{tabular}{|c|}
$\dfrac{
\begin{tabular}{c}
$H$
\end{tabular}
}
{
\raisebox{-4pt}{
\begin{tabular}[t]{c}
$G$
\end{tabular}}
}$\\$G$ and $H$ are terms
\end{tabular}
\end{document}