3

The following produces undesirable output because the "tails" of the vectors are overlapping and hard to see. Is there a way to automate something better by having all vectors draw only 95% of their distance?

Is there an even a better solution than the one I prescribed?

Additionally, how can one swap up the arrowhead -> for a closed arrow -|>?

\begin{tikzpicture}[scale=1.5]
%\tkzInit[xmin=-3,xmax=7,ymin=-6,ymax=5] \tkzGrid
\tkzInit

\tkzDefPoint(0,0){A}
\tkzDefPoint(4,0){B}
\tkzDefPoint(5,-3){C}
\tkzDefPoint(1,-3){D}

\draw[thick,->] (A) -- (B) node[above] {$B$};
\draw[thick,<-] (B) -- (C) node[below] {$C$};
\draw[thick,<-] (C) -- (D) node[below] {$D$};
\draw[thick,->] (D) -- (A) node[above] {$A$};

\tkzDefMidPoint(B,D) \tkzGetPoint{E}
\draw[thick,->] (D) -- (E) node[above] {$E$};
\draw[thick,->] (C) -- (E);
\draw[thick,->] (E) -- (A);
\draw[thick,->] (E) -- (B);

\end{tikzpicture}

enter image description here

vrbatim
  • 731
  • 6
  • 13
  • To avoid this problem, one of my colleague (math teacher) simply puts the arrow at the middle of the path :-) – Franck Pastor Mar 27 '15 at 05:27
  • Wouldn't that system become confusing if, say, I had to draw a vector from A halfway to B? – vrbatim Mar 27 '15 at 05:36
  • No, if you only place only the arrow tip itself in the middle of the segment. Without drawing another segment, only the tip. See http://tex.stackexchange.com/questions/234689/how-to-mark-a-segment-with-an-arrow-in-tkz-euclid-with-the-tkzmarksegment – Franck Pastor Mar 27 '15 at 12:45

3 Answers3

2

A workaround would be to chose full arrow tips, and to reduce the angle of these tips while increasing their length accordingly. Since I don't know much about tikz and less about its arrows, here is an example with MetaPost, in which I've changed the default values of the relevant parameters ahlength and ahangle to suit the figure.

Included in a LuaLaTeX program for typesetting convenience:

\documentclass[border=2bp]{standalone}
\usepackage{luamplib}
  \mplibsetformat{metafun}
  \mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
  numeric u; u = 1.5cm;
  pair A, B, C, D, E; 
  A = origin; B = (4u, 0); C = u*(5, -3); D = u*(1, -3);
  E = .5[B, D] = .5[A, C];
  beginfig(1);
    ahangle := 22.5; % default 45°
    ahlength := 8bp; % default 4 bp
    drawarrow A -- B;
    drawarrow B -- C;
    drawarrow C -- D;
    drawarrow D -- A;
    drawarrow D -- E;
    drawarrow C -- E;
    drawarrow E -- A;
    drawarrow E -- B;
    freelabeloffset := 1.5bp;
    for str = "A", "B", "C", "D":
      freelabel("$" & str & "$", scantokens str, E);
    endfor
    label.top("$E$", E);
  endfig;
\end{mplibcode}
\end{document}

Before the changes to ahlength and ahangle:

enter image description here

After the changes:

enter image description here

Franck Pastor
  • 18,756
  • 1
    I've just noticed that there is currently a post whose author seeks to recreate with tikz the same kind of arrows than with MetaPost: http://tex.stackexchange.com/questions/235283/how-does-the-angle-key-from-arrows-meta-tikz-library-work. It can serve as a complement to my answer :-) – Franck Pastor Mar 27 '15 at 15:01
1

You can use shorten per line basis. There is no global (automatic solution) change possible since the directions are different here. To swap arrow head from -> to -|>, use \usetikzlibrary{arrows.meta} and do -|>..

\documentclass[a4paper]{article}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{arrows.meta}
\begin{document}
  \begin{tikzpicture}[scale=1.5]
%\tkzInit[xmin=-3,xmax=7,ymin=-6,ymax=5] \tkzGrid
\tkzInit

\tkzDefPoint(0,0){A}
\tkzDefPoint(4,0){B}
\tkzDefPoint(5,-3){C}
\tkzDefPoint(1,-3){D}

\draw[thick,->,shorten >=.5mm] (A) -- (B) node[above] {$B$};
\draw[thick,<-,shorten <=.5mm] (B) -- (C) node[below] {$C$};
\draw[thick,<-,shorten <=.5mm] (C) -- (D) node[below] {$D$};
\draw[thick,->,shorten >=.5mm] (D) -- (A) node[above] {$A$};

\tkzDefMidPoint(B,D) \tkzGetPoint{E}
\draw[thick,->,shorten >=.5mm] (D) -- (E) node[above] {$E$};
\draw[thick,->,shorten >=.5mm] (C) -- (E);
\draw[thick,->,shorten >=.7mm] (E) -- (A);
\draw[thick,->,shorten >=.5mm] (E) -- (B);

%% arrow head

\draw[thick,-|>] (C) -- +(2cm,0);

\end{tikzpicture}
\end{document}

enter image description here

1

Global options are not a problem actually. You just define a style and change the direction of the arrows in the \draw command, i.e. you always say "draw an arrow from x to y" and y is the where the arrow points.

Also for closed arrow tips, you should look at the arrows library of tikz. A simple one is -stealth.

\documentclass[a4paper]{article}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{arrows.meta}
\begin{document}
  \begin{tikzpicture}[
    scale=1.5,
    ar/.style={thick, -stealth, shorten >=.5mm}]
  \tkzInit

  \tkzDefPoint(0,0){A}
  \tkzDefPoint(4,0){B}
  \tkzDefPoint(5,-3){C}
  \tkzDefPoint(1,-3){D}

  \draw[ar] (A) -- (B) node[above] {$B$};
  \draw[ar] (C) -- (B) node[below] {$C$};
  \draw[ar] (D) -- (C) node[below] {$D$};
  \draw[ar] (D) -- (A) node[above] {$A$};

  \tkzDefMidPoint(B,D) \tkzGetPoint{E}
  \draw[ar] (D) -- (E) node[above] {$E$};
  \draw[ar] (C) -- (E);
  \draw[ar] (E) -- (A);
  \draw[ar] (E) -- (B);

  %% arrow head

  \draw[thick,-|>] (C) -- +(2cm,0);

 \end{tikzpicture}
 \end{document}