Graphics, Figures & TablesTikz styles: global and local

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
theo moore
Posts: 72
Joined: Thu Jan 15, 2009 3:16 pm

Tikz styles: global and local

Post by theo moore »

Hi!

Question: How do you change (pin) styles locally and globally? For
example, if I want one sort of pin, I can define at the beginning of
my document:

Code: Select all

\tikzset{%
every pin/.style={fill=gray!10, rectangle, rounded corners=3pt}
}
Then simply use a command such as

Code: Select all

\node[pin=0:{Pin Text}] at (0,0) {};
to create a pin. Every pin will be subject to the global style.

Now suppose that within a tikzpicture, I wanted another type of style.
I tried something like this:

Code: Select all

\node[pin/.style={circle}, pin=0:{Pin Text}] at (0,0) {};
But it does not seem to work. How do I:
(a) Change the style for one particular node
(b) Define multiple styles (at the beginning of my document, say) and
use them on command?

Here is a minimal example:

Code: Select all

\documentclass[11pt]{article}

\usepackage{tikz}

\tikzset{%
every pin/.style={fill=gray!50, rectangle, rounded corners=3pt}
}

\begin{document}

\begin{tikzpicture}
\node[pin=0:{Pin Text}] at (0,0) {};
\end{tikzpicture}

\begin{tikzpicture}
\node[pin/.style={circle}, pin=0:{Pin Text}] at (0,0) {};
\end{tikzpicture}

\end{document}
Thanks!
Last edited by theo moore on Fri Apr 08, 2011 6:44 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Tikz styles: global and local

Post by shadgrind »

One possibility is to unset the global pin style and set the pin style per tikzpicture:

Code: Select all

\documentclass[11pt]{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[every pin/.style={fill=gray!50, rectangle, rounded corners=3pt}]
\node[pin=0:{Pin Text}] at (0,0) {};
\end{tikzpicture}

\begin{tikzpicture}[every pin/.style={circle}]
\node[pin=0:{Pin Text}] at (0,0) {};
\end{tikzpicture}

\end{document}
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
theo moore
Posts: 72
Joined: Thu Jan 15, 2009 3:16 pm

Tikz styles: global and local

Post by theo moore »

shadgrind wrote:One possibility is to unset the global pin style and set the pin style per tikzpicture:

Code: Select all

\documentclass[11pt]{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[every pin/.style={fill=gray!50, rectangle, rounded corners=3pt}]
\node[pin=0:{Pin Text}] at (0,0) {};
\end{tikzpicture}

\begin{tikzpicture}[every pin/.style={circle}]
\node[pin=0:{Pin Text}] at (0,0) {};
\end{tikzpicture}

\end{document}
Hi, unfortunately, this won't work for my purposes. I, in fact, have to change the pin properties within the SAME tikzpicture environment.

I'm sorry for not mentioning that, as I was trying to simplify my explanation of the problem.
theo moore
Posts: 72
Joined: Thu Jan 15, 2009 3:16 pm

Re: Tikz styles: global and local

Post by theo moore »

I wanted to bump this up, as I still haven't managed to find a satisfactory solution. :(
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Tikz styles: global and local

Post by shadgrind »

Per node in the same tikzpicture:

Code: Select all

\documentclass[11pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[pin={[fill=gray!50, rectangle, rounded corners=3pt]0:{Pin Text}}] at (0,1) {};
\node[pin={[circle]0:{Pin Text}}] at (0,0) {};
\end{tikzpicture}
\end{document}
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
theo moore
Posts: 72
Joined: Thu Jan 15, 2009 3:16 pm

Tikz styles: global and local

Post by theo moore »

Perfect. Thank you.

For future reference, you can then define a style using

Code: Select all

\tikzstyle{mystyle}=[circle]
and then use it in a pin via

Code: Select all

\node[pin={[style=mystyle]0:{Pin Text}}] at (0,0) {};
Post Reply