5

I want to draw this:

enter image description here

and my xy-pic code is

\[
\xy
@={(0,0),(10,0),(10,10),(0,10)},
{\ar@{-}^{f_1}|{\dir{>}} s0;s1},
{\ar@{-}^{f_2}|{\dir{>}} s1;s2},
{\ar@{-}^{f_3}|{\dir{>}} s2;s3},
{\ar@{-}^{f_4}|{\dir{>}} s3;s0},
\endxy
\]

Can I use the function @@ to simplify the above code? For example, the code

\[
\xy
@={(0,0),(10,0),(10,10),(0,10)},
s0="prev",
@@{;"prev";**@{-}="prev"}
\endxy
\]

gives the output without the arrows and the f's.

3

TikZ implementation with very simple code:

\documentclass[tikz,border=10pt]{standalone}

\begin{document}
\begin{tikzpicture}[-stealth,line cap=rect]
\draw(0,0)  |- (1,1)  node[above]{$f_1$};
\draw(1,1)  -| (2,0)  node[right]{$f_2$};
\draw(2,0)  |- (1,-1) node[below]{$f_3$};
\draw(1,-1) -| (0,0)  node[left]{$f_4$};
\end{tikzpicture}
\end{document}

enter image description here

2

A PSTricks solution where you can control the side length in the diagram (by changing the value of \Length):

\documentclass{article}

\usepackage{pstricks-add}
\usepackage{xfp}

\newcommand*\halfLength{\fpeval{\Length/2}}
\newcommand*\maximum{\fpeval{\Length+0.5}}

\def\Length{5}


\begin{document}

\begin{pspicture}(-0.5,-0.5)(\maximum,\maximum)
  \psline[
    ArrowInside = ->,
    ArrowInsidePos = 0.52,
    arrowscale = 1.5
  ](0,0)(0,\Length)(\Length,\Length)(\Length,0)(0,0)
  \uput[ 90](\halfLength,\Length){$f_{1}$}
  \uput[  0](\Length,\halfLength){$f_{2}$}
  \uput[270](\halfLength,0){$f_{3}$}
  \uput[180](0,\halfLength){$f_{4}$}
\end{pspicture}

\end{document}

output

Note that I haven't choosen ArrowInsidePos = 0.5 but instead ArrowInsidePos = 0.52 since this gives a better arrowhead placement (visually speaking), I think.

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.