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've a small problem in Tikz. I try to draw arrows within 4 dimensions. Every arrow should have equal length. My implementation right now works with coordinates. There is a rectangle with a center point and in each direction a point at the edge. I'd like to draw an arrow from the center in each direction with the same size. Right now I draw between the center and this construct: ($(center)!0.5!(borderpoint)$). The problem with that is, it differs between the short an width edges but I'd like to have the same length in every direction.

Example:

\draw[thick] (0,0) -- (6,0) -- (6,3) -- (0, 3) -- cycle;
\draw[->, thick] (3,1.5) -- ($(3,1.5)!0.5!(0,1.5)$);
\draw[->, thick] (3,1.5) -- ($(3,1.5)!0.5!(6,1.5)$);
\draw[->, thick] (3,1.5) -- ($(3,1.5)!0.5!(3,3)$);
\draw[->, thick] (3,1.5) -- ($(3,1.5)!0.5!(3,0)$);
\shade[shading=ball, ball color=black!90] (3,1.5) circle (0.25em);

Arrows

I wish to: draw an arrow from Startpoint in direction of DestPoint for an length of X. :))

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can specify which is the length of the arrow in this way:

\draw[->, thick] (3,1.5) -- ($(3,1.5)!1cm!(0,1.5)$);

where the length is 1cm.

Here is the revised example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}


\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) -- (6,0) -- (6,3) -- (0, 3) -- cycle;
\draw[->, thick] (3,1.5) -- ($(3,1.5)!1cm!(0,1.5)$);
\draw[->, thick] (3,1.5) -- ($(3,1.5)!1cm!(6,1.5)$);
\draw[->, thick] (3,1.5) -- ($(3,1.5)!1cm!(3,3)$);
\draw[->, thick] (3,1.5) -- ($(3,1.5)!1cm!(3,0)$);
\shade[shading=ball, ball color=black!90] (3,1.5) circle (0.25em);
\end{tikzpicture}
\end{document}

The result:

enter image description here

You can find more information on the calc library on the documentation (13.5 Coordinate Calculations, pgfmanual version October 25, 2010).


A quickest implementation:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newlength\arrowlength
\setlength{\arrowlength}{1cm}
\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) -- (6,0) -- (6,3) -- (0, 3) -- cycle;
\foreach \destination in 
{{0,1.5},{6,1.5},{3,3},{3,0}}
\draw[->, thick] (3,1.5) -- ($(3,1.5)!\arrowlength!(\destination)$);
\shade[shading=ball, ball color=black!90] (3,1.5) circle (0.25em);
\end{tikzpicture}
\end{document}
share|improve this answer
    
Ah ok,this is strange. i tried this befor and i did not work at all. with this knowledge now i modified my graphic. i found that if i do something like this: \pgfmathsetmacro{\arrowSize}{1cm} it won't work. I'll try a bit more, thanks so far. –  Alex Oct 11 '12 at 9:14
1  
No, you should use \pgfmathsetlength{\arrowlength}{1cm}; in the quickest implementation you can absolutely substitute \setlength{\arrowlength}{1cm} with \pgfmathsetlength{\arrowlength}{1cm} without problems. –  Claudio Fiandrino Oct 11 '12 at 9:18
    
very cool. thank you very much. daily improvements. i like :) –  Alex Oct 11 '12 at 9:31

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.