2

I have written the code for a diagram in tikzpicture which does exactly what I want. The only problem is that the arrows overlap with the symbols and the picture does not scale correctly. I could not figure out (yet) why this happens. This is the code:

\begin{tikzpicture}
\node (A) {$A$};
\node (C) [right of=A] {$C$};
\node (B) [below of=A] {$B$};
\node (D) [right of=B] {$D$};
\node (E) [node distance=1.4cm, left of=A, below of=A, above of=B] {$\mathscr{E}$};
\draw[->] (A) to node {$f_1$} (B);
\draw[->] (A) to node {$f_2$} (C);
\draw[->] (C) to node {$f_3$} (D);
\draw[->] (B) to node {$f_4$} (D);
\draw[->, bend left] (E) to node [swap] {$f$} (A);
\draw[->, bend right] (E) to node {$g$} (B);
\end{tikzpicture}

2 Answers 2

2

Just use the simpler syntax of tikz-cd:

\documentclass{article}
\usepackage{amssymb, amsfonts, mathrsfs}%
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
 & A \rar["f_2"]\dar["f_1"]&C\dar["f_3"] \\
\mathscr{E}\urar[bend left, "f"]\rar[bend right, "g", swap] &B \rar["f_4"] & D
\end{tikzcd}

\end{document} 

enter image description here

1

You can just add in the TikZ option [auto] for the node label to be placed automatically next to the arrow, and also for your swap option to be applicable.

In this solution, I took the liberty to place swap wherever necessary to make the output look decent. You can adjust as you wish. I also took the liberty to make the labels on the arrows slightly smaller than the main nodes. It looks better to my eye, at least.

You can scale the picture by enclosing the TikZ code in the command \scalebox{<len>}{<tikz code>}, as I did here.

tikz sizes

\documentclass{article}
\usepackage{tikz}
\usepackage{mathrsfs}
\newcommand\santker{%
    \begin{tikzpicture}[auto] % <------------
    \node (A) {$A$};
    \node (C) [right of=A] {$C$};
    \node (B) [below of=A] {$B$};
    \node (D) [right of=B] {$D$};
    \node (E) [node distance=1.4cm, left of=A, below of=A, above of=B] {$\mathscr{E}$};
    \begin{scope}[every node/.style = {font=\footnotesize}] % <------------
    \draw[->] (A) to node[swap] {$f_1$} (B);
    \draw[->] (A) to node {$f_2$} (C);
    \draw[->] (C) to node {$f_3$} (D);
    \draw[->] (B) to node[swap] {$f_4$} (D);
    \draw[->, bend left] (E) to node {$f$} (A);
    \draw[->, bend right] (E) to node [swap] {$g$} (B);
    \end{scope}
    \end{tikzpicture}
}
\begin{document}
    \scalebox{0.5}{\santker}

    \bigskip

    \santker

    \bigskip

    \scalebox{2}{\santker}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .