alignmentmathjax

Is there a way to create multiple tables in Mathjax using only one $$...$$?


Originally asked on Tex.SE (10K+ rep link), however it was deemed off-topic and was recommended that I ask this here

I am currently editing my question on Biology.SE to clean up some grammar issues, and would also like to fix the Mathjax formatting for my Punnett squares, as I want to display it using only one $$...$$ block.

I have the following code for the Punnett squares:

$$
\begin{align}
                           | \; & \underline{\text{ A }} \; | \; \underline{\text{ a }} \; | \\
\underline{\overline A} \; | \; & \underline{AA}            | \; \underline{Aa}            | \\
                      a \; | \; & Aa                     \; | \; aa                     \; |
\end{align}
$$
$$
\begin{align}
                           | \; & \underline{\text{ B }} \; | \; \underline{\text{ b }} \; | \\
\underline{\overline B} \; | \; & \underline{BB}            | \; \underline{Bb}            | \\
                      b \; | \; & Bb                     \; | \; bb                     \; |
\end{align}
$$
$$
\begin{align}
                           | \; & \underline{\text{ C }} \; | \; \underline{\text{ c }} \; | \\
\underline{\overline C} \; | \; & \underline{CC}            | \; \underline{Cc}            | \\
                      c \; | \; & Cc                     \; | \; cc                     \; |
\end{align}
$$

however, when I try to delete one of the $$$$ pairs, I get the following error:

Erroneous nesting of question structures.

enter image description here


My question is: If it is possible, how can I go about putting multiple tables in one $$...$$ block? Could I just use arrays to solve this problem?


Solution

  • You could do

    <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
    
    \begin{align}
    \begin{aligned}
                               | \; & \underline{\text{ A }} \; | \; \underline{\text{ a }} \; | \\
    \underline{\overline A} \; | \; & \underline{AA}            | \; \underline{Aa}            | \\
                          a \; | \; & Aa                     \; | \; aa                     \; |
    \end{aligned}\\
    \\
    \begin{aligned}
                               | \; & \underline{\text{ B }} \; | \; \underline{\text{ b }} \; | \\
    \underline{\overline B} \; | \; & \underline{BB}            | \; \underline{Bb}            | \\
                          b \; | \; & Bb                     \; | \; bb                     \; |
    \end{aligned}\\
    \\
    \begin{aligned}
                               | \; & \underline{\text{ C }} \; | \; \underline{\text{ c }} \; | \\
    \underline{\overline C} \; | \; & \underline{CC}            | \; \underline{Cc}            | \\
                          c \; | \; & Cc                     \; | \; cc                     \; |
    \end{aligned}
    \end{align}

    Note the change from align to aligned within the outer align.

    But I'm wondering if you don't actually mean something more like

    <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
    
    \begin{align}
    \begin{array}{c|c|c|}
      & A  & a  \\ \hline
    A & AA & Aa \\ \hline
    a & Aa & aa \\ \hline
    \end{array}\\
    \\
    \begin{array}{c|c|c|}
      & B  & b  \\ \hline
    B & BB & Bb \\ \hline
    b & Bb & bb \\ \hline
    \end{array}\\
    \\
    \begin{array}{c|c|c|}
      & C  & c  \\ \hline
    C & CC & Cc \\ \hline
    c & Cc & cc \\ \hline
    \end{array}
    \end{align}