2

I am trying to typeset an equation in display mode between a pair of diagrams generated by \xymatrix, where these diagrams have been centered vertically on the line using \vcenter. The equation as a whole is wider than the textwidth, so I want to center it. I can't find a good solution how to do this, and the two things I've used elsewhere don't work. I can't really break it up into two lines, as I've got more complex examples for which I'm not sure it would work (in an \align multi-line environment, with the same ingredients, for instance). I'm working with a journal-provided template, and the ams packages in the MWE below are as provided, I'm not sure I can change those (even if reloading them does little).

\documentclass[12pt]{amsart}
\usepackage{amsmath, amsthm, amscd, amsfonts} %these are all as provided, I can't change these

\usepackage[all]{xy}
\usepackage{lipsum}

\newcommand{\diagram}[1]{\vcenter{\hbox{\xymatrix{#1}}}} % also breaks without the \hbox
\newcommand{\equals}{\quad=\quad}  

\begin{document}

\lipsum[2]
\[
% \centerline{%  doesn't work
% \noindent\makebox[\textwidth]{%  also doesn't work
\hspace{-2cm} % works, but is bad
\diagram{xxxxxxxxxx \ar[r] & xxxx \ar@/^1.5pc/[r] \ar@/_1.5pc/[r] & xxx }
\equals
\diagram{&& xxxxx \ar[dr] \\
    xxxxxxxxxx \ar@/^/[urr] 
    \ar@/_/[drr] \ar[r] & 
    v^{[2]} \ar[ur] \ar[dr] && xxx\\
    && xxxxx \ar[ur]}%
% }
\]
\lipsum[2]

\end{document}

I'm pretty sure the problem is in the interaction between the \vcenter and the horizontal alignment commands I'm trying, but that is kinda the point. The MWE example currently gives what I want, but not how I want it.

2 Answers 2

2

I,m not familiar with xy package, so I use tikz-cd which is also intended for such diagrams. However, problem is the same at both diagrams.

For centering your "equations! in center of text, you can use changepage package:

\documentclass[12pt]{amsart}%{article}
\usepackage{amsmath, amsthm, amscd} %these are all as provided, I can't change these

%\usepackage[all]{xy}
\usepackage{tikz-cd}
\usepackage{lipsum}

\newcommand{\diagram}[1]{\vcenter{\hbox{\xymatrix{#1}}}} % also breaks without the \hbox
\newcommand{\equals}{\quad=\quad}

\usepackage[strict]{changepage}
\begin{document}

\lipsum[2]
\begin{adjustwidth}{-6em}{-6em}
\centering
    \begin{tikzcd}[baseline]
xxxxxxxxxx \ar[r]   & xxxx \ar[r, bend left] &  xxx \ar[l,bend left]
    \end{tikzcd}%
\equals%
    \begin{tikzcd}[baseline=-1ex]
        &   & xxxxx \ar[dr]          &       \\
xxxxxxxxxx \ar[r] \ar[urr,bend left]
                  \ar[drr, bend right]    
        &  v^{[2]}\ar[ur]  
                  \ar[dr] 
            &               & xxx   \\
        &   & xxxxx \ar[ur] &        
    \end{tikzcd}
\end{adjustwidth}
\lipsum[2]

\end{document}

enter image description here

Addendum: You can merge bot diagrams in one and reduce separation between nodes. After this this equation become narrower:


\documentclass[12pt]{amsart}%{article}
\usepackage{amsmath, amsthm, amscd} %these are all as provided, I can't change these

%\usepackage[all]{xy}
\usepackage{tikz-cd}
\usepackage{lipsum}

\newcommand{\diagram}[1]{\vcenter{\hbox{\xymatrix{#1}}}} % also breaks without the \hbox
\newcommand{\equals}{\quad=\quad}

\usepackage[strict]{changepage}
\begin{document}

\lipsum[2]
\begin{adjustwidth}{-2.4em}{-2.4em}
%\rule{\linewidth}{1pt}
    \centering%
    \begin{tikzcd}[sep=small]
    &   &   &   &   & xxx \ar[dr]
                        &           \\
xxxxxxxxxx \ar[r]   
    & xxxx \ar[r, bend left] 
        & xxx\equals \ar[l,bend left]
            &   \hspace{-1.5em}
                xxxxxxxxxx \ar[r] \ar[urr,bend left] \ar[drr, bend right]    
                &  v^{[2]}  \ar[ur] \ar[dr] 
                    &   & xxx       \\
    &   &   &   &   & xxxxx \ar[ur] 
                        &        
    \end{tikzcd}
\end{adjustwidth}
\lipsum[2]

\end{document}

enter image description here

2

It's not so difficult to center an oversized equation, but I'd recommend splitting it across lines.

Instead of \vcenter, use gathered, which employs the same mechanism, but in a more user friendly way.

I redefined \diagram to also accept options for \xymatrix; so I can reduce a bit the gap between columns and get a slightly less wide object.

\documentclass[12pt]{amsart}
\usepackage{amsmath, amsthm, amscd, amsfonts} %these are all as provided, I can't change these

\usepackage[all]{xy}
\usepackage{lipsum}

\newcommand{\diagram}{}% to be sure it isn't defined
\def\diagram#1#{\diagramaux{#1}}% collect everything up to the first {
\newcommand\diagramaux[2]{\begin{gathered}\xymatrix#1{#2}\end{gathered}}

\newcommand{\equals}{\quad=\quad}

\begin{document}

\lipsum[2]
\[
\hspace{1000pt minus 2000pt}
\diagram@C-8pt{xxxxxxxxxx \ar[r] & xxxx \ar@/^1.5pc/[r] \ar@/_1.5pc/[r] & xxx }
\equals
\diagram@C-8pt{&& xxxxx \ar[dr] \\
    xxxxxxxxxx \ar@/^/[urr]
    \ar@/_/[drr] \ar[r] &
    v^{[2]} \ar[ur] \ar[dr] && xxx\\
    && xxxxx \ar[ur]}
\hspace{1000pt minus 2000pt}
\]
\lipsum[2]

\end{document}

The trick is to have flexible glue on either side. The big natural size tells TeX to squeeze the spaces as much as possible (nothing done, actually, in this case); but then the large shrink components do the job of centering with no overfull.

enter image description here

1
  • Thanks for this. It works for some, but in places I'd already split it (using align*) and this method dies. Jan 14, 2021 at 5:39

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.