4

Minimal example:

\documentclass{report}
\usepackage{amsmath}

\begin{document}

\begin{alignat*}{2}
    A \hspace{12.5pt} & \hspace{12.5pt} && A \\[10pt]
    B \\[10pt]
    C \hspace{12.5pt} & \hspace{12.5pt} && C \\[10pt]
    D \hspace{12.5pt} & \hspace{12.5pt} && D
\end{alignat*}

\begin{alignat*}{2}
    A \hspace{12.5pt} & \hspace{12.5pt} && A \\
\end{alignat*}
\begin{equation*}
    B 
\end{equation*}
\begin{alignat*}{2}
    C \hspace{12.5pt} & \hspace{12.5pt} && C \\[10pt]
    D \hspace{12.5pt} & \hspace{12.5pt} && D
\end{alignat*}

\end{document}

I'd like the B to be centered with equal vertical space between the lines.

Edit.

My original question was not sufficiently precise. I do not want the horizontal spacing between the aligned columns to change. In practice the entries will be quite wide. Please see the new example.

\documentclass{report}
\usepackage{amsmath}

\begin{document}

\begin{alignat*}{2}
    A \hspace{12.5pt} & \hspace{12.5pt} && A \\[10pt]
    MMMMMMMMMMMMMM \\[10pt]
    C \hspace{12.5pt} & \hspace{12.5pt} && C \\[10pt]
    D \hspace{12.5pt} & \hspace{12.5pt} && D
\end{alignat*}

\begin{alignat*}{2}
    A \hspace{12.5pt} & \hspace{12.5pt} && A \\
\end{alignat*}
\begin{equation*}
    MMMMMMMMMMMMMM 
\end{equation*}
\begin{alignat*}{2}
    C \hspace{12.5pt} & \hspace{12.5pt} && C \\[10pt]
    D \hspace{12.5pt} & \hspace{12.5pt} && D
\end{alignat*}

\end{document}

It should look like this:

        A    A
    MMMMMMMMMMMMMM
        C    C
        D    D

2 Answers 2

1

You can use a gather with some box measurements (provided by \eqmathbox through eqparbox):

enter image description here

\documentclass{article}

\usepackage{amsmath,eqparbox}

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
  \IfValueTF{#1}
    {\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
    {\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
  \mathpalette\eqmathbox@{#3}
}
\makeatother

\begin{document}

\begin{alignat*}{2}
         A \hspace{12.5pt} & \hspace{12.5pt} && AA      \\[10pt]
                                  BBB                   \\[10pt]
      CCCC \hspace{12.5pt} & \hspace{12.5pt} && CCCCC   \\[10pt]
    DDDDDD \hspace{12.5pt} & \hspace{12.5pt} && DDDDDDD
\end{alignat*}

\begin{alignat*}{2}
         A \hspace{12.5pt} & \hspace{12.5pt} && AA      \\
\end{alignat*}
\begin{equation*}
                                  BBB 
\end{equation*}
\begin{alignat*}{2}
      CCCC \hspace{12.5pt} & \hspace{12.5pt} && CCCCC   \\[10pt]
    DDDDDD \hspace{12.5pt} & \hspace{12.5pt} && DDDDDDD
\end{alignat*}

\begin{gather*}
        \eqmathbox[LHS][r]{A} \hspace{25pt} \eqmathbox[RHS][l]{AA}      \\[10pt]
                                  BBB                                   \\[10pt]
     \eqmathbox[LHS][r]{CCCC} \hspace{25pt} \eqmathbox[RHS][l]{CCCCC}   \\[10pt]
  \eqmathbox[LHS][r]{DDDDDDD} \hspace{25pt} \eqmathbox[RHS][l]{DDDDDDD}
\end{gather*}

\end{document}

The Left Hand Sides are measured and stored in a box of maximum width (all right-aligned) and the Right Hand Sides are put in a different box of maximum width (all left-aligned).


You can also use an array:

enter image description here

\[
  \renewcommand{\arraystretch}{2}% https://tex.stackexchange.com/q/31672/5764
  \begin{array}{ r @{\hspace{25pt}} l }
         A & AA               \\
      \multicolumn{2}{c}{BBB} \\
      CCCC & CCCCC            \\
    DDDDDD & DDDDDDD
  \end{array}
\]
6
  • When I try to typeset your example I get the error Undefined control sequence. \NewDocumentCommand{\eqmathbox}{o O{c} m}{% ? Jan 25 at 20:03
  • 2
    @simplejack: Add \usepackage{xparse} to your preamble. Up-to-date LaTeX distributions won't need this.
    – Werner
    Jan 25 at 20:30
  • Thanks, now I am able to typeset the example. However, the eqmathboxes do not seem to work with prooftrees from the package ebproof as their contents. I had to put them inside of braces to make alignat work. Jan 25 at 20:45
  • 1
    @simplejack: M'kay. Can you provide some code that show the current, complete, minimal example? You can use Pastebin if you wish.
    – Werner
    Jan 25 at 21:37
  • 1
    @simplejack: Riiight. That's another option. For reference, I'll add it to my current answer.
    – Werner
    Jan 25 at 22:29
5

You can place equations within \intertext to pause and resume alignment.

\documentclass{report}
\usepackage{amsmath}

\begin{document}

\begin{alignat*}{2}
    A \hspace{12.5pt} & \hspace{12.5pt} && A \\
\intertext{\[ MMMMMMMMMMMMMM \]}
    C \hspace{12.5pt} & \hspace{12.5pt} && C \\[10pt]
    D \hspace{12.5pt} & \hspace{12.5pt} && D
\end{alignat*}

\end{document}

PDFLaTeX sample

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.