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 would like to draw a coordinate system along some lines in a framework for a structural course. This little coordinate system is called local coordinate system.

At the moment the framework looks like this:

\documentclass{article} % say
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}[scale=1,inner sep=0pt,thick,dot/.style={draw,circle,minimum size=4pt}]

\draw [help lines] (0,0) grid (3,4);
\node[dot] (2) at (0,0) [label={[label distance=1mm]270:2}] {};
\node[dot] (3) at (0,2) [label={[label distance=1mm]180:3}] {};
\node[dot] (1) at (0,4) [label={[label distance=1mm]90:1}] {};
\node[dot] (4) at (3,2) [label={[label distance=1mm]0:4}] {};
\node[dot] (5) at (2.5,4) [label={[label distance=1mm]45:5}] {};


\draw   (2) -- (3) node [midway,sloped,below] {3};
\draw   (3) -- (4) node [midway,above,sloped] {4};      
\draw   (2) -- (4) node [midway,above,sloped] {6};      


%\draw [<->] (0,0.8) -- (0,0) -- (0.8,0);
%\draw[->] (-.1,1) -- (-.6,1) node[right] {$y$} coordinate(y axis);
%\draw[->] (-.1,1) -- (-.1,1.5) node {$x$} coordinate(x axis);

\end{tikzpicture}

\end{document}

Picture of the result of the code above

And I want something like this:

How I want it to look like

But I don't know how to do that. Does anyone know that? And how do I get some space between the numbers on the lines?

share|improve this question
add comment

2 Answers

One possibility is to use markings decorations. One can also define the mirror case where it goes below the line or can appear with extra options provided by the user but the idea is essentially the same.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,decorations.markings}
\begin{document}
\begin{tikzpicture}[scale=1,inner sep=0pt,thick,dot/.style={draw,circle,minimum size=4pt},
put coord sys/.style={
decoration={markings,
mark= at position 0.5
with
{
\draw[latex-latex,ultra thin] (2pt,2pt) +(5mm,0) -| +(0,5mm) 
        node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle y$};
\path (2pt+5mm,2pt) 
        node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle x$};

}
},
postaction=decorate}]

\draw [help lines] (0,0) grid (3,4);
\node[dot] (2) at (0,0) [label={[label distance=1mm]270:2}] {};
\node[dot] (3) at (0,2) [label={[label distance=1mm]180:3}] {};
\node[dot] (1) at (0,4) [label={[label distance=1mm]90:1}] {};
\node[dot] (4) at (3,2) [label={[label distance=1mm]0:4}] {};
\node[dot] (5) at (2.5,4) [label={[label distance=1mm]45:5}] {};


\draw[put coord sys]   (2) -- (3);
\draw[put coord sys]   (3) -- (4);      
\draw[put coord sys]   (2) -- (4);      

\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
It would be slightly better if the two lines are drawn in one path so that the line join at (2pt,2pt) looked better. –  Qrrbrbirlbel Jun 10 '13 at 21:50
    
@Qrrbrbirlbel Yes, indeed. Fixed it now. –  percusse Jun 10 '13 at 22:11
    
Thank you soo much! This was exactly what I was looking for! And it worked very well :) –  ArtWooD Jun 11 '13 at 13:30
    
@ArtWooD My pleasure. –  percusse Jun 11 '13 at 17:31
add comment

With PSTricks:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\psset{labels=none,ticks=none,arrows=->}
\begin{document}
\begin{pspicture}[showgrid=true](5,5)
    \rput{30}(2,2){\psaxes(0,0)(-1,-1)(2,2)[$x$,0][$y$,90]}
\end{pspicture}
\end{document}

enter image description here

Explanation:

  • \psset{labels=none,ticks=none,arrows=->} sets the axes without labels, without ticks but with arrows pointing upward and to the right.
  • \psaxes(0,0)(-1,-1)(2,2)[$x$,0][$y$,90] draws the axes and the axis names.
  • \rput{30}(2,2){...} rotates and translates the axes.

Miscellaneous:

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pst-plot,pst-eucl}
\psset{labels=none,ticks=none,arrows=->,saveNodeCoors}
\addtopsstyle{gridstyle}{gridlabels=0pt}

\begin{document}
\begin{pspicture}[showgrid=true](5,4)
    \pstGeonode[CurveType=polygon,PointName=none](0,0){A}(5,3){B}(0,3){C}
    \rput{!N-B.y N-B.x atan}(2.3,1.6){\psaxes[linecolor=blue](0,0)(1,1)[$x$,0][$y$,90]}
\end{pspicture}
\end{document}

enter image description here

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.