4

How do I set labeling styles associated with each style type?

For example: (source below)

  • I have an "input" style (medium circle) and a "junction" style (small dot) which I would like to have the labels below by default, but they default to above.
  • I also have a "block" style (gradient shaded rectangle) which somehow already has the label default to below, and I want to use a smaller font for the label.

I can't figure out how to do either of these, the only thing I could figure out is how to use the every label/.style to change the font of all labels.

https://www.writelatex.com/read/jrwtbtqxntyz

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit}
\begin{document}
\begin{tikzpicture}[node distance=5mm,
    block/.style={
    % The shape:
    rectangle, minimum size=6mm,
    % The rest
    thick,draw=black,
    top color=white,
    bottom color=black!10
    },
    input/.style={
    % The shape:
    circle, minimum size=1mm,
    % The rest
    thick,draw=black,
    fill = white,
    },
    junction/.style={
    % The shape:
    circle, minimum size=0.5mm, inner sep=0pt,
    % The rest
    thick,draw=black,
    fill = black
    },
    every label/.style={
        font=\small
    },
    >=latex
    ]
\node (wcmd) [input, label=below:$\omega_{cmd}$]{};
\node (wcmd2) at (0,1) [input, label=$\omega_{cmd}$]{};
\node (jj) at (1,1) [junction, label=Z] {};
\node (C) [block, right=of wcmd] {C};
\node (D) [block,right=of C] {D};
\node (E) [block,right=of D, label=below:Hey] {E};
\node (F) [block,below=of D] {F};
\draw[->] (wcmd) -- (C);
\draw[->] (C) -- (D);
\end{tikzpicture}
\end{document}

1 Answer 1

5

If you want to have differentiated attributes for labels under different style, one way is to add label in the definition of those styles. For example, if I want labels in the block style to be red, with small font and default position at north east, I'd define the block style as

block/.style={
  <list of other keys>,
  label={[red,font=\small]above left: #1},
}

and use \node[block={<label text>}]{<node text>};, where block takes one argument (which can be empty) that specifies the label text.

Full Code

\documentclass\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit}
\begin{document}
\begin{tikzpicture}[node distance=5mm,
    block/.style={
    % The shape:
    rectangle, minimum size=6mm,
    % The rest
    thick,draw=black,
    top color=white,
    bottom color=black!10,
    label={[red,font=\small]above right:#1},    % label for 'block'
    },
    input/.style={
    % The shape:
    circle, minimum size=1mm,
    % The rest
    thick,draw=black,
    fill = white,
    label={[orange,font=\tiny]below:#1}         % label for 'input'
    },
    junction/.style={
    % The shape:
    circle, minimum size=0.5mm, inner sep=0pt,
    % The rest
    thick,draw=black,
    fill = black,
    label={[blue,font=\footnotesize]below:#1}   % label for 'junction'
    },
    >=latex
    ]
\node (wcmd) [input=$\omega_{cmd}$]{};
\node (wcmd2) at (0,1) [input=$\omega_{cmd}$]{};
\node (jj) at (1,1) [junction=Z] {};
\node (C) [block, right=of wcmd] {C};
\node (D) [block,right=of C] {D};
\node (E) [block={Hey},right=of D] {E};
\node (F) [block,below=of D] {F};
\draw[->] (wcmd) -- (C);
\draw[->] (C) -- (D);
\end{tikzpicture}
\end{document}

Output

enter image description here

2
  • does the label position=below work within a particular style? (not just the "every label" style) My question really isn't about the "every label" style; I want to control the label attributes within a particular style.
    – Jason S
    Commented Jun 5, 2014 at 20:30
  • @JasonS: I updated my answer. Is this what you're looking for?
    – Herr K.
    Commented Jun 5, 2014 at 20:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .