Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I don't want to change style only. I want to create node that takes 3 numbers and display them with appropriate decorations. For instance:

\mynode{5,6,7} 

Should display node with "a=5", "b=6" and "c=7" inside in 3 lines.

Update:

I have this code:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath}

\newcommand{\statnode}[3]{
  \node[rectangle, draw]{
    $\begin{aligned}
      n &= #1 \\ 
      \text{sum} &= #2 \\ 
      \mu &= #3
    \end{aligned}$
  }
}

\newcommand{\statnodex}[3]{
  node[rectangle, draw]{
    $\begin{aligned}
      n &= #1 \\ 
      \text{sum} &= #2 \\ 
      \mu &= #3
    \end{aligned}$
  }
}

\begin{document}

\begin{tikzpicture}[
    level distance=100,
  ]

  \statnode{1}{10}{0.1}
  child {
    \statnodex{1}{10}{0.1}
  };
\end{tikzpicture}
\end{document}

But:

  • it is ugly to have 2 commands
  • it renders incorrectly for some reason
share|improve this question
    
I want these nodes to be usable within TikZ tree (child command). –  Łukasz Lew Aug 8 '10 at 14:31
    
would it be possible to test (via some if statement) whether or not you are inside a \node command? –  Yossi Farjoun Aug 8 '10 at 15:53
1  
It seems to me that the main issue is not that there is a double definition, but rather that the author must differentiate between using \statnode and \statnodex, similarto having to use \node vs. node in tikz –  Yossi Farjoun Aug 8 '10 at 16:44
    
Yes, that is exactly the problem –  Łukasz Lew Aug 9 '10 at 12:05
add comment

3 Answers

  • Put the part, that both commands have in common, into another macro.
  • use anchor=north if you would like to draw the line to the top but not further
share|improve this answer
    
anochor=north seems to have problems with deeper trees. –  Łukasz Lew Aug 8 '10 at 15:48
add comment

If you change the code which draws the tree you can use only one of your custom node macros:

  \draw \statnodex{1}{10}{0.1}
        child {
               \statnodex{1}{10}{0.1}
        };

\node is just syntactic sugar for \draw node.

Now you could get really fancy and define a new multi-part node (see "Shapes with Multiple Text Parts" in the PGF manual, which is Section 39.6 in the 2.00 version) but unless you want to do this in many documents a macro seems fine.

share|improve this answer
add comment

Would the TikZ "chains" library work for your application?

Quick hack of your code to demonstrate:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{positioning}
\usepackage{amsmath}

\newcommand{\statnode}[3]{
  \node[rectangle, draw, on chain]{
    $\begin{aligned}
      n &= #1 \\ 
      \text{sum} &= #2 \\ 
      \mu &= #3
    \end{aligned}$
  }
}

\newcommand{\statnodex}[3]{
  \node[rectangle, draw, on chain=going below, join]{
    $\begin{aligned}
      n &= #1 \\ 
      \text{sum} &= #2 \\ 
      \mu &= #3
    \end{aligned}$
  }
}

\begin{document}

\begin{tikzpicture}[
    start chain,
    node distance=5mm
  ]

  \statnode{1}{10}{0.1};
  \statnodex{1}{10}{0.1};

\end{tikzpicture}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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