TeX - LaTeX Asked on November 1, 2021
Consider a line
draw[->] (0,0) -- (1, 0);
Is it somehow possible to make the line stop at e.g. 70% of the way from the start coordinate (0,0)
to the end coordinate (1,0)
, i.e. so that the arrow head is at (0.7,0)
?
Of course without explicitly calculate that point manually. I’d like to define the two endpoints, but then draw the line and sto before we actually get to that end point.
EDIT: I hope this ASCII art makes it a little bit clearer:
(0,0) (.7,0) (1,0)
--------------->
Just to complete Zarko's answer, it's possible to use calc
library to stop the line at a certain percentage of its lenght. shorten
option allows to do it when we exactly know the distance to be shortened, but when this distance is unknown or want a percentatge, calc
is better.
documentclass[tikz, margin=3mm]{standalone}
usetikzlibrary{arrows.meta,
positioning,
calc}
begin{document}
begin{tikzpicture}
node[circle, inner sep=1pt, fill] (A) {};
node[circle, inner sep=1pt, fill, right=2cm of A] (B) {};
node[circle, inner sep=1pt, fill] at (0,5mm) {};
node[circle, inner sep=1pt, fill] at (4,15mm) {};
draw [-Straight Barb] (A) -- node[above, sloped] {70%} ($(A)!.7!(B)$);
draw [-Straight Barb] (0,5mm) -- node[above, sloped] {95%} ($(0,5mm)!.95!(4,15mm)$);
end{tikzpicture}
end{document}
Answered by Ignasi on November 1, 2021
One of possible solution is use of decorations.markings
TikZ library:
documentclass[tikz, margin=3mm]{standalone}
usetikzlibrary{arrows.meta,
decorations.markings}
begin{document}
begin{tikzpicture}[
decoration={markings,% switch on markings
mark=at position 0.7 with {arrow{Straight Barb}}}
]
draw [postaction={decorate}] (0,0) -- (1,0);
end{tikzpicture}
end{document}
Addendum:
From OP comment follows quite unusual demand (not clear from question). It seems, that (s)he looking for something like this:
documentclass[tikz, margin=3mm]{standalone}
usetikzlibrary{arrows.meta,
decorations.markings}
begin{document}
begin{tikzpicture}[
decoration={markings,% switch on markings
mark=at position 0.7 with {arrow{Straight Barb}}}
]
draw [postaction={decorate}] (0,0) -- (1,0);
draw [-Straight Barb] (0,-2mm) -- (0.7*1,-2mm);
end{tikzpicture}
end{document}
what is the same if you draw the second line as
draw [-Straight Barb] (0,-2mm) -- (0.7,-2mm);
or
draw [-Straight Barb, shorten >=3mm] (0,-2mm) -- (1,-2mm);
Frankly said, I do not understand your intention.
Answered by Zarko on November 1, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP