## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Defining a Local Style (Not in Preamble) to Add Arrowhead at a point on line Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
Faseeh
Posts: 12
Joined: Mon Jan 04, 2016 10:23 am

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

Hi All,

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/38548/arrows-and-nodes-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

Stefan Kottwitz
Site Admin
Posts: 9388
Joined: Mon Mar 10, 2008 9:44 pm
Hi Faseeh,

in that post, the style and options are defined locally and not in the preamble. The style won't work in another tikzpicture:

\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}

We get the error message Package pgfkeys Error: I do not know the key '/tikz/nodewitharrow' since it's local.

Stefan
Site admin

Faseeh
Posts: 12
Joined: Mon Jan 04, 2016 10:23 am
Hi Stephan,

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: 9388
Joined: Mon Mar 10, 2008 9:44 pm
Hi Faseeh!

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
Site admin

Faseeh
Posts: 12
Joined: Mon Jan 04, 2016 10:23 am
Thanks you Stephan for the correction. You are right....

Yours truly,
Faseeh

Return to “Graphics, Figures & Tables”

### Who is online

Users browsing this forum: No registered users and 2 guests