[Tex/LaTex] How to draw labeled parallel arrows in commutative diagram with TikZ

diagramstikz-pgf

I want to draw labeled parallel arrow in commutative diagram with TikZ, I searched on google and Tex Stackexchange, however, I found only the method to draw parallel arrow by transform canvas only, I tried to add the labeled but it failed.

Here is my picture:

enter image description here

I want to label a map from $\mathfrak{P}=\bigoplus_{i\inI}\mathfrak{P_{i}}$ to $\mathfrak{P_{i}}$ and from $\mathfrak{P_{i}}$ to $\mathfrak{P}=\bigoplus_{i\inI}\mathfrak{P_{i}}$, i.e the arrows of the square.

Here is the code :

\begin{tikzpicture}[node distance=2.8cm, auto]
\node (P) {$\mathfrak{P}=\bigoplus_{i\in I}\mathfrak{P_{i}}$};
\node(Q)[right of=P] {$\mathfrak{P_{j}}$};
\node (B) [below of=P] {$\mathfrak{B}$};
\node (C) [right of=B] {$\mathfrak{C}$};
\draw[transform canvas={yshift=0.5ex},->] (P) - -(Q);
\draw[transform canvas={yshift=-0.5ex},->](Q) -- (P); 
\draw[->](Q) to node {$a$}(B);
\draw[->](Q) to node {$a$}(C);
\draw[->] (P) to node {$\pi_{j}$} (B);
\draw[->] (B) to node {$\psi$} (C);
\draw[->, dashed] (Q) to node [swap] {$g$} (B);
\end{tikzpicture}

Best Answer

Here are your labeled lines.

There are other ways to shift nodes but IMO the transform canvas is the most direct, so you are doing fine for that aspect.

To label a line, you can add a node command at the end of the line specification. The label may be placed above or below and you can specify where along the line with keywords such as midway or the more general pos=<fraction along line>. I also shifted the diagonal lines so that they may both be seen (since one was dashed).

I added a macro to simplify the shifting of the diagonal lines.

\documentclass[border=5pt]{standalone}

\usepackage{amsmath,amssymb}

\usepackage{tikz}
\usetikzlibrary{calc}


\begin{document}

\begin{tikzpicture}[node distance=2.8cm, auto]

\pgfmathsetmacro{\shift}{0.3ex}

\node (P) {$\mathfrak{P}=\bigoplus_{i\in I}\mathfrak{P_{i}}$};
\node(Q)[right of=P] {$\mathfrak{P_{j}}$};
\node (B) [below of=P] {$\mathfrak{B}$};
\node (C) [right of=B] {$\mathfrak{C}$};

\draw[transform canvas={yshift=0.5ex},->] (P) --(Q) node[above,midway] {\tiny top};
\draw[transform canvas={yshift=-0.5ex},->](Q) -- (P) node[below,midway] {\tiny bottom}; 
\draw[->](Q) to node {$a$}(C);
\draw[->] (P) to node[swap] {$\pi_{j}$} (B);
\draw[->,dashed] (B) to node {$\psi$} (C);

\draw[->,transform canvas={xshift=-\shift,yshift=\shift}](Q) to node {$a$}(B);
\draw[->, dashed,transform canvas={xshift=\shift,yshift=-\shift}] (Q) to node[swap] {$g$} (B);

\end{tikzpicture}

\end{document}

enter image description here