Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

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

share|improve this answer
add comment

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{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff
\newcommand*\halfLength{\calc{\Length/2}}
\newcommand*\maximum{\calc{\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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.