TikZ Alignment – Elegant Methods to Align Two TikZ Diagrams in a Single Line

alignmenttikz-cd

I wish to put two tikz diagrams in a same line so that they are aligned, centered on the quarters as below:

enter image description here

The only way I know for now is to put the tikz diagrams in a common equation and then add spaces by hand, for example:

\[
\begin{tikzcd}
\ast\times X\arrow[r,"{(1,1_X)}"]\arrow[dr,swap,"\cong"] & G\times X\arrow[d,"\alpha"]\\
&X
\end{tikzcd}
%
\qquad\qquad
%
\begin{tikzcd}
G\times G\times X\arrow[r,"{(m,1_X)}"]\arrow[d,swap,"{(1_G,\alpha )}"] & G\times 
X\arrow[d,"\alpha"]\\
G\times X \arrow[r,"\alpha"]&X
\end{tikzcd}
\]

To adjust the spacing is really a waste of time, so I'd like to know whether there is any elegant way that aligns the diagram automatically.

Thanks in advance.

Best Answer

  • in equation environment had not to be empty lines
  • it is not entirely unclear, what you mean with centering.

Is the following simple solution close to what you after?

enter image description here

(red lines shows text borders)

\documentclass{article}
\usepackage{tikz-cd}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\[
\begin{tikzcd}[column sep=large]
\ast\times X\arrow[r,"{(1,1_X)}"]\arrow[dr,swap,"\cong"] & G\times X\arrow[d,"\alpha"]\\
&X
\end{tikzcd}
%
\qquad
%
\begin{tikzcd}[column sep=large]
G\times G\times X\arrow[r,"{(m,1_X)}"]\arrow[d,swap,"{(1_G,\alpha )}"] & G\times
X\arrow[d,"\alpha"]\\
G\times X \arrow[r,"\alpha"]&X 
\end{tikzcd}
\]
\end{document}

Addendum: It seems that OP looking for the following:

enter image description here

(red lines indicate text borders, vertical black lines show positions of image bisectors)

\documentclass{article}
\usepackage{tabularx}
    \newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage{tikz-cd}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\noindent\begin{tabularx}{\linewidth}{ C | C } % in real document delete `|`
\begin{tikzcd}[column sep=large,
               ampersand replacement=\&]
\ast\times X\arrow[r,"{(1,1_X)}"]\arrow[dr,swap,"\cong"]
    \& G\times X\arrow[d,"\alpha"]\\
    \&   X
\end{tikzcd}
    &   \begin{tikzcd}[column sep=large,
               ampersand replacement=\&]
        G\times G\times X\arrow[r,"{(m,1_X)}"]\arrow[d,swap,"{(1_G,\alpha )}"]
        \&  G\times
            X\arrow[d,"\alpha"]\\
        G\times X \arrow[r,"\alpha"]
        \&  X
        \end{tikzcd}    \\
    \vline  & \vline  % in real document delete this code line
\end{tabularx}
\end{document}