# writing around the square

I hope there was no similar thread (at least I wasn't able to find). I have problem in writing such a thing in latex:

I would be grateful for any hint. Thanks in advance!

• You can use tikzcd library for TikZ. Google commutative diagram in tikz Nov 17, 2015 at 23:26
• Welcome! Have you tried anything? Can you at least post the code for the bits you need assembled? (It is annoying for people to have to copy from a graphic when writing an answer.)
– cfr
Nov 17, 2015 at 23:28
• I know how to write basic equations, but didn't know how to create such a diagram. Now, I think it can be done also using 3 x 3 matrix. Nov 17, 2015 at 23:47
• What's up with the title?:)' Nov 18, 2015 at 1:23

This is a commutative diagram, for which the Xy package is particularly useful.

\documentclass{article}
\usepackage{amsmath}
\usepackage[all]{xy}
\begin{document}
$\xymatrix{ X_n\ar[r]^{\text{a.s.}} \ar@{=}[d]^D & X\ar@{=}[d]^D\\ Y_n & Y }$
\end{document}


The package is really versatile for drawing commutative diagrams; check out the documentation for all of the things you can do to decorate objects and arrows.

• I usually add cmtip to the options of xy, so the arrow tips are like the standard ones. Nov 18, 2015 at 0:23

Another option is tikz-cd:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}

\begin{document}

$\begin{tikzcd} X_n \arrow[r,"\text{a.s.}"] \arrow[d,shift right=.15em,equal,"D"] & X \arrow[d,equal,"D"]\\ Y_n & Y \end{tikzcd}$

\end{document}


The argument to \arrow (in brackets) has the direction, possible options like equal for getting an “equals sign” instead of an arrow, or swap for changing the side of the label (default is the left side looking in the direction of the target); with shift right we can move it to the right in order to correct the visual effect induced by the presence of the subscripts; finally, between double quotes, the label.

• I'm curious about the little grey horizontal lines at the edges of the double lines? Why they appear? Nov 18, 2015 at 1:22
• @CroCo Good question! It's a bug in the TikZ arrow library, in my opinion. Nov 18, 2015 at 7:12
• @CroCo Note that printers shouldn't print them. The bug can be also blamed to the browsers and their mistakes in anti-aliasing.
– yo'
Nov 18, 2015 at 16:31
• @yo' No, it's a bug nonetheless: the problem is that the object is realized by filling black a rectangle and then drawing a white rectangle to mask of the center part. Try and issue \pagecolor{blue} and you'll see. Nov 18, 2015 at 16:32
• @egreg That's clearly explained in the manual. From this point of view, it's a documented feature.
– yo'
Nov 18, 2015 at 16:47

A demo of what can be done with pstricks and with tikz-cd:

\documentclass{article}
\usepackage{amsmath}
\usepackage{pst-node}
\usepackage{tikz-cd}
\usepackage{auto-pst-pdf}

\begin{document}
%
$\psset{arrows=->, arrowinset=0.15, linewidth=0.5pt, nodesep=3pt, labelsep=2pt, rowsep=0.6cm, colsep = 1.1cm, shortput=nab} \everypsbox{\scriptstyle} \begin{psmatrix} %%%nodes \smash[b]{X_n} & X \\% Y_n & Y %%% arrows \ncline{1,1}{1,2}^{a. s.} \psset{arrows=none, doubleline, doublesep=1.4pt} \ncline{1,1}{2,1}>{D} \ncline{1,2}{2,2}>{D} \end{psmatrix}$

$\begin{tikzcd} X_n \arrow{r}{a. s.} \arrow[equal]{d}{D} & X \arrow[equal]{d}{D} \\% Y_n & Y \end{tikzcd}$
\end{document}


A Tikz solution

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
node distance =.7cm
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\node (A)               {$\textbf{X}_{\textbf{n}}$};
\node (B) [right=of A]  {$\textbf{X}$};
\node (C) [below=of B]  {$\textbf{Y}$};
\node (D) [below=of A]  {$\textbf{Y}_{\textbf{n}}$};

\draw[->,thick] (A) -- node[above] {a.s.} (B);
\draw[double,thick] (A) -- node[right] {D}(D);
\draw[double,thick] (B) -- node[right] {D}(C);
\end{tikzpicture}
\end{document}


The result is

This is only a sketch. Some tuning probably needed. (I am assuming, that it is about probability, not commutative diagrams).

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\def\eqD{\stackrel{D}{=}}
\def\roteqD{\rotatebox{-90}{$\eqD$}}

$\begin{array}{c@{}c@{}c} X_n&\;\stackrel{\mathrm{a.s.}}{=}\;&X\\[-7pt] \roteqD &&\roteqD\\[5pt] Y_n&&Y \end{array}$

\end{document}

• Adding a snapshot for the output of the code is always appreciated. Possible upvotes as well. Nov 18, 2015 at 1:25