2

I want to locally overwrite a global style.

For the MWE: In the second picture "t=2" should be right of node c respectively d.

MWE:

\documentclass[tikz]{standalone}

\tikzset{%
one/.style args = {#1}{label=right: o{=}#1},%
two/.style args = {#1}{label={[yshift=-1em]right: t{=}#1}}%
}

\begin{document}

\begin{tikzpicture}
\node at (0,0) [one=1,two=2] {a};
\node at (2,0) [one=1,two=2] {b};
\end{tikzpicture}

%locally shift the label up again
\begin{tikzpicture}
\node at (0,0) [two=2] {c};
\node at (2,0) [two=2] {d};
\end{tikzpicture}

\end{document}

output

  • @JouleV thanks! adding [two/.style args = {#1}{label={right: t:#1}}] to the second picture totally did it. – Ben Mar 7 at 13:46
  • 2
    We'd like to keep answers separate from questions, so you should write a separate answer instead of editing your answer into the question. Self-answers are perfectly admissible, and a well-written answer may earn you additional reputation. – Kurt Mar 7 at 14:40
  • 1
    I don't know if here is a written or unwritten rule: "Whenever someone writes a comment, but no answer, go for it and write the answer yourself. This person automatically quits its 'right' on the reputation". – Ben Mar 8 at 14:12
  • 1
    I rolled-back, voted for reopen and am very willing to write an answer myself. Unless @JouleV wants to do so – Ben Mar 8 at 14:14
  • 1
    My comment was written because you added the solution to your question. You can of course ask @JouleV to answer, because it was his comment solving the question. If he does not answer you can of course add an answer ... Voted to reopen ... – Kurt Mar 8 at 15:21
2

This answer bases on JouleV's comment to my question.


Instead of trying to edit the global style (which was my idea beforehand) by something like

\begin{tikzpicture}[two/.append style = {label={[yshift=0]}}]

or

\node at (0,0) [two={[yshift=0]2}] {c};

which both does not work, simply literally overwrite the style by:

\begin{tikzpicture}[two/.style args = {#1}{label={right: t{=}#1}}]

Full code:

\documentclass[tikz]{standalone}

\tikzset{%
one/.style args = {#1}{label=right: o{=}#1},%
two/.style args = {#1}{label={[yshift=-1em]right: t{=}#1}}%
}

\begin{document}

\begin{tikzpicture}
\node at (0,0) [one=1,two=2] {a};
\node at (2,0) [one=1,two=2] {b};
\end{tikzpicture}

%locally shift the label up again
\begin{tikzpicture}[two/.style args = {#1}{label={right: t{=}#1}}]
\node at (0,0) [two=2] {c};
\node at (2,0) [two=2] {d};
\end{tikzpicture}

\end{document}

output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.