Graphics, Figures & Tables ⇒ Defining a Local Style (Not in Preamble) to Add Arrowhead at a point on line
Defining a Local Style (Not in Preamble) to Add Arrowhead at a point on line
Thank you for going through the post. I am trying to add arrow head in middle (or at certain point) on a line. I searched web and found thread that solves the problem, here it is: https://tex.stackexchange.com/questions ... es-in-tikz
..But the problem is that it adds the style/all the options to the document preamble, not in the tikz picture that i am creating. The picture i am creating need to be a standalone picture so that it can be moved without any reference to preamble.
Is there any way i can define it like below:
\begin{tikzpicture}
[some options for nodes and arrlow,
first style/.style={blah},
second style/.style={blub}] ...
\draw[mystyle](0,0)--(1,0)
\end{tikzpicture}
I really like the idea presented here to keep styles local but i am unable to implement it. Kindly help.
https://tex.stackexchange.com/a/52379/146240
Thank you,
Faseeh
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
Defining a Local Style (Not in Preamble) to Add Arrowhead at a point on line
in that post, the style and options are defined locally and not in the preamble. The style won't work in another
tikzpicture
:Code: Select all
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
[
nodewitharrow/.style 2 args={
decoration={
markings,
mark=at position {#1} with {
\arrow{>},
\node[transform shape,above] {#2};
}
},
postaction={decorate}
}
]
\draw[nodewitharrow={0.6}{Node text},nodewitharrow={0.2}{Second}] (0,0) -- (4,3) ;
\draw[nodewitharrow={0.75}{\tiny Tiny}] (0,0) (4,0) arc (0:60:2);
\end{tikzpicture}
\begin{tikzpicture}
\draw[nodewitharrow={0.6}{Node text},nodewitharrow={0.2}{Second}] (0,0) -- (4,3) ;
\draw[nodewitharrow={0.75}{\tiny Tiny}] (0,0) (4,0) arc (0:60:2);
\end{tikzpicture}
\end{document}
Stefan
Defining a Local Style (Not in Preamble) to Add Arrowhead at a point on line
Thank you so much, I was unable to respond quickly, really sorry for that.
Yes you are right, I was overlooking it. But can i do it without using decoration.marking (or by using arrows.meta).
Actually i was trying to do it without referring to this package, with options that are defined in node. Like using node[midway, option to ad arrow in middle or at some position like arrow_pos=0.7].
Is it possible or i am just overthinking.

Thank you!
Faseeh
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
Defining a Local Style (Not in Preamble) to Add Arrowhead at a point on line
decoration.marking and arrows.meta belong to TikZ. For me, it doesn't make much sense to avoid using a part of TikZ but do the same by own programming. Why? Don't you have a complete TikZ? Or is it to save a line in the preamble? It looks like if one likes to use the book class but doesn't want the \chapter command and asks for doing the same chapter headings with TOC etc. in a manual way.

Stefan
Defining a Local Style (Not in Preamble) to Add Arrowhead at a point on line

Yours truly,
Faseeh