5

I define a new command \nonBranchingRule that takes 3 arguments. Intuitively, it defines a rule where the last argument is a comment (optional argument) for the rule. I want to place the comment under the rule and center both. I do it with tabular. I add tabular lines to test the real arrangement of a rule and a comment.

MWE below:

\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}

I would like to get the second case but with \nonBranchingRule I am getting the first one.

enter image description here

4

You had the #1 #2 #3` in the wrong order, and an unused optional argument.

Here I show two forms \nonBranchingRule with three mandatory arguments and \nonBranchingRuleB where the rule argument is optional argument given first, in [].

\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}
3
  • Sorry I added that the comment is optional. That is why order was different. So, in your solution how to accommodate a comment as optional? Feb 25 '15 at 14:50
  • 1
    @FiboKowalsky \newcommand can only make #1 optional, and the syntax would be \zzz[optional comment]{top}{bottom} with the optional argument in [] not {} Feb 25 '15 at 15:29
  • 1
    @FiboKowalsky answer updated showing optional argument form Feb 25 '15 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.