2

I am not very familiar with the tikz package. Reading here and there on internet, I managed to do this

\begin{tikzpicture}
  [node distance=.8cm,
  start chain=going below,]
     \node[punktchain, join] (Telegrapher){Telegrapher's equations $\begin{aligned}
          \frac{d}{d z} {\vec V} \left(z,s\right) &=-\vec Z'(s){\vec I}\left(z,s\right) \\
       \frac{d}{d z} {\vec I} \left(z,s\right) &=-\vec Y'(s){\vec V} \left(z,s\right)\label{test}
       \end{aligned}$};
     \node[punktchain, join] (test) {test};
  \end{tikzpicture}

with this definitions for the nodes:

\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}
\tikzset{
>=stealth',
  punktchain/.style={
    rectangle, 
    rounded corners, 
    % fill=black!10,
    draw=black, very thick,
    text width=25em, 
    minimum height=3em, 
    text centered, 
    on chain},
  line/.style={draw, thick, <-},
  element/.style={
    tape,
    top color=white,
    bottom color=blue!50!black!60!,
    minimum width=8em,
    draw=blue!40!black!90, very thick,
    text width=10em, 
    minimum height=3.5em, 
    text centered, 
    on chain},
  every join/.style={->, thick,shorten >=1pt},
  decoration={brace},
  tuborg/.style={decorate},
  tubnode/.style={midway, right=2pt},
}

Now my question is: in my node, I have an equation. I would like it to be numbered as all the other equations in my latex, or at least I would like to be able to refer to it. Now I have used \label{test}, but when I refer with \ref{label} it seems to take the section as a reference.

Do you know how to properly refer to an equation built inside a node, in a graph?

Arun Debray
  • 7,126
  • 2
  • 30
  • 54
  • What happens when using \begin{align} instead of $\begin{aligned} and \end{align} instead of \end{aligned}$ ? – Vincent Nivoliers Apr 30 '15 at 11:27
  • It tells me that align is only allowed using paragraph mode... – user123349 Apr 30 '15 at 11:41
  • 1
    Then you could probably use the align environment in a minipage as in this example – Vincent Nivoliers Apr 30 '15 at 11:47
  • There is no equation number hence no reference. Use either equation or align (if you want numbers for all lines) –  Apr 30 '15 at 11:53
  • The minipage environments works great, thanks @VincentNivoliers . I think that now my node and my box definitions have some incompability, because the equations have numbers, but the number goes on a new line. This is what I have used for the box option \tikzstyle{mybox} = [draw=black, very thick, rectangle, rounded corners, inner sep=10pt, inner ysep=20pt] – user123349 Apr 30 '15 at 12:13
  • Fixed! I put \begin{minipage}{0.90\textwidth} instead of \begin{minipage}{0.50\textwidth} and it works fine! Thank you! – user123349 Apr 30 '15 at 12:19
  • You should then post your final solution as an answer for future use since comments are not the right way of answering a question. – Vincent Nivoliers Apr 30 '15 at 12:38
  • I'm voting to close this question as off-topic because it has been solved by its author himself. – yo' Dec 25 '15 at 23:08

1 Answers1

2

Since a solution was constructed in the comments, but never posted as an answer, here's the solution, for anyone who has this problem in the future. Credit goes to the users in the comments to this question.

If you want an equation number to reference, use the equation or align environments, but by default this doesn't work inside a TikZ node. Thus, you can wrap it in a minipage: \begin{minipage}{0.9\textwidth}...\end{minipage}, which allows the use of align. Now, cross-referencing works as usual, and it even works with hyperref.

Also, a minor nitpick: if you're just using regular-sized parentheses, it's better to use ( and ) instead of \left( and \right), because the spacing is a little nicer. See this post for more details.

Here's the code that makes this work.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}
\tikzset{
% ... same settings as in the question post ... 
}
\usepackage[colorlinks=true]{hyperref}
\begin{document}
\begin{tikzpicture}
  [node distance=.8cm,
  start chain=going below,]
     \node[punktchain, join] (Telegrapher){Telegrapher's equations
     % Here's the difference: a minipage and align environment
     \begin{minipage}{0.9\textwidth}
     \begin{align}
       % now, we can use \label, \ref, and \eqref as usual
       \frac{d}{d z} \vec V(z,s) &= -\vec Z'(s)\vec I(z,s) \label{test1}\\
       \frac{d}{d z} \vec I(z,s) &= -\vec Y'(s)\vec V(z,s) \label{test2}
       \end{align}
       \end{minipage}};
     % Reference from another node
     \node[punktchain, join] (test) {Test: reference to equation~\eqref{test1}.};
  \end{tikzpicture}

% References from outside the tikzpicture also work
Reference to equation~\eqref{test2}.
\end{document}

And here's a picture of the PDF output.

enter image description here

Arun Debray
  • 7,126
  • 2
  • 30
  • 54
  • This should be community wiki. Otherwise, you are claiming credit for it, whatever you say. Alternatively, you can leave a comment suggesting that one of the commentators post an answer. – cfr Dec 25 '15 at 23:18
  • @cfr: someone left a comment suggesting that a while back, which is why I posted this. In any case, it's CW now. – Arun Debray Dec 26 '15 at 00:59
  • I just meant 'that's the other option'. I certainly think a community wiki write up is useful, especially if such a comment has not resulted in an answer from somebody who commented. – cfr Dec 26 '15 at 01:23