LaTeX forum ⇒ Graphics, Figures & TablesDefining 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

Postby Faseeh » Thu Apr 04, 2019 11:28 am

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

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

Postby Stefan Kottwitz » Thu Apr 04, 2019 4:13 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:

  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary{decorations.markings}
  4. \begin{document}
  5.  
  6. \begin{tikzpicture}
  7. [
  8. nodewitharrow/.style 2 args={
  9. decoration={
  10. markings,
  11. mark=at position {#1} with {
  12. \arrow{>},
  13. \node[transform shape,above] {#2};
  14. }
  15. },
  16. postaction={decorate}
  17. }
  18. ]
  19.  
  20. \draw[nodewitharrow={0.6}{Node text},nodewitharrow={0.2}{Second}] (0,0) -- (4,3) ;
  21. \draw[nodewitharrow={0.75}{\tiny Tiny}] (0,0) (4,0) arc (0:60:2);
  22. \end{tikzpicture}
  23.  
  24. \begin{tikzpicture}
  25. \draw[nodewitharrow={0.6}{Node text},nodewitharrow={0.2}{Second}] (0,0) -- (4,3) ;
  26. \draw[nodewitharrow={0.75}{\tiny Tiny}] (0,0) (4,0) arc (0:60:2);
  27. \end{tikzpicture}
  28. \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

Postby Faseeh » Tue Apr 09, 2019 9:28 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. :D

Thank you!
Faseeh

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

Postby Stefan Kottwitz » Tue Apr 09, 2019 1:49 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

Postby Faseeh » Fri Apr 12, 2019 8:49 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