2

I am trying to display two vectors in two differnt nodes, and then, link some elements using arrows.

\tikzstyle{line} = [draw, -latex']        
    \begin{tikzpicture}[node distance = 2cm,auto,remember picture]
        % Place nodes       
        \node [draw,rounded corners] (node1) {$\matrix[mymatrix, name=M1]{
                                                                1 \\
                                                        |[!]|   2\rho\pi \\
                                                        |[draw,rounded corners,fill=blue]|   3\\
                                                    }$};

     \node [draw,rounded corners] (node1) {$\matrix[mymatrix, name=M2]{
                                                                4 \\
                                                        |[!]|   2\lambda\pi \\
                                                        |[draw,rounded corners,fill=yellow]|   3\\
                                                    }$};    
   \draw [red, >=stealth, <->, shorten <= 3pt, shorten >=3 pt]
 (M1-2-1.south east) to[bend left=60] (M2-3-1.north east);     
    \end{tikzpicture}

In my Tikz Preamble I have the following package declaration

\documentclass{article,fleqn}
\usepackage{tikz,amsmath, amssymb,bm,color,automata,matrix,positioning,fit}
\usepackage[margin=0cm,nohead]{geometry}
\usepackage[active,tightpage]{preview}
\usetikzlibrary{shapes,arrows}
% needed for BB
\usetikzlibrary{calc}
\usetikzlibrary{topaths}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{calc}
\usetikzlibrary{tikzmark}

\usetikzlibrary{topaths}
\usetikzlibrary{backgrounds}
\usepackage{todonotes}

%To be able to use 
\tikzset{
    !/.style = {
        fill=yellow!30,
    },
    mymatrix/.style = {
        matrix of math nodes,
        left delimiter  = (,
        right delimiter = ),
        nodes={minimum width=6ex},
    }
}
\tikzset{every picture/.style=remember picture}

\PreviewEnvironment{tikzpicture}

Probably , i am using more then required, but I do have other files. Tikz is giving me the following error:

Package amsmath Error: Old form '\matrix' should be \begin{\matrix}..de[draw,rounded corners](node1){$\matrix(followed by: [mymatrix, na 

I already used that in Latex (Thanks to the help of some stackeschange users), but I can't seem to make it work in Tikz If anyone has a suggestion, then please...

Cheers.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
user2536125
  • 1,165
  • Why \documentclass{article,fleqn}? Why \matrix inside $...$? Why \matrix inside a \node? – Gonzalo Medina Jul 15 '13 at 22:16
  • Hi @GonzaloMedina, You can just discard those, since with TikzEdt, we use the same Preamble for different files. Hence, these are required by other files and not this specific example. – user2536125 Jul 15 '13 at 22:20
  • But there are so many syntactic problems here... To begin with, you are using fleqn in the mandatory argument of \documentclass, you are loading tikz libraries as packages. Is that a special feature of TikXEdt? – Gonzalo Medina Jul 15 '13 at 22:59
  • As far as I know, yes, but still, I am no expert. – user2536125 Jul 15 '13 at 23:02
  • @GonzaloMedina No it is not. @Op I agree here with Gonzalo. TikZEdt is nothing but a editor for TikZ (and a neat parser/visualizer for basic paths). You should be able to simply use the tikzpicture (and needed \usetikzlibrary) here. Why have you changed so much compared to percusse’s answer anyway? – Qrrbrbirlbel Jul 16 '13 at 02:33
  • @Qrrbrbirlbel, I didn't change anything, I only asked Tikz to draw the nodes with rounded corners, and did copy and past for the preamble. This later contains more then percusse's answer simply because as I said early, it is used for other files as well. – user2536125 Jul 16 '13 at 06:45
  • @user2536125Perhaps if you describe exactly what your intent is, someone could offer assistance. As I see from the code, you want both vectors to be surrounded by a rounded corner rectangle; how should they appear: side by side, one below the other? – Gonzalo Medina Jul 16 '13 at 21:53
  • @GonzaloMedina I want them to appear one after the other. But I wonder how come the code cannot be more robust, i.e ,select the location within the code as a node, the filling, surrounding..etc – user2536125 Jul 16 '13 at 22:15
  • @user2536125 there are robust methods, of course, but you didn't tell from the beginning (in the other question) your complete intent, and this made things a little bit complicated. Please see my answer below for two different approaches. – Gonzalo Medina Jul 17 '13 at 02:39
  • 1
    Incidentally, the reason you are getting that specific error is because you are putting \matrix inside \node. When TikZ starts a node then it unloads all of its commands and thus \matrix reverts to its original definition. As you've loaded amsmath then this is its matrix command. – Andrew Stacey Jul 17 '13 at 09:45

1 Answers1

4

Your code has a lot of syntactical problems.

In the code below I show two possibilities; the highlighting was done using the \tcbhighmath command from the tcolorbox package; the additional arrows were drawn with the help of the tikzmark library:

\documentclass{article}
\usepackage{amsmath}
\usepackage[most]{tcolorbox}
\usetikzlibrary{tikzmark,positioning}

\tcbset{
myformulai/.style={
  colback=yellow!30,
  colframe=yellow!30,
  left=2pt,right=2pt,top=0pt,bottom=0pt,
  },
myformulaii/.style={
  colback=blue!30,
  boxrule=0.4pt,
  colframe=blue!30!black,
  left=2pt,right=2pt,top=0pt,bottom=0pt,
  },
myformulaiii/.style={
  colback=white,
  colframe=black,
  boxrule=0.4pt,
  left=2pt,right=2pt,top=0pt,bottom=0pt,
  }
}

\begin{document}

\[
\tcbhighmath[myformulaiii]{%
\begin{pmatrix}
     1 \\ \tcbhighmath[myformulai]{2\rho\pi\tikzmark{a}} \\ \tcbhighmath[myformulaii]{3}
\end{pmatrix}}
\]

\[
\tcbhighmath[myformulaiii]{%
\begin{pmatrix}
     1 \\ \tcbhighmath[myformulai]{2\rho \pi} \\ \tcbhighmath[myformulaii]{3}\tikzmark{b}
\end{pmatrix}}
\]

\begin{tikzpicture}[remember picture, overlay]
\draw [red, >=stealth, <->, shorten <= 3pt, shorten >=3 pt,overlay]
 (pic cs:a) to[bend left=90] (pic cs:b);
\end{tikzpicture}

\begin{center}
\begin{tikzpicture}[remember picture, overlay]
\node[rounded corners,draw] (mat1)
{
$\begin{pmatrix}
     1 \\ \tcbhighmath[myformulai]{2\rho\pi\tikzmark{c}} \\ \tcbhighmath[myformulaii]{3}
\end{pmatrix}$
};

\node[rounded corners,draw,below=of mat1] (mat2)
{
$\begin{pmatrix}
     1 \\ \tcbhighmath[myformulai]{2\rho \pi} \\ \tcbhighmath[myformulaii]{3}\tikzmark{d}
\end{pmatrix}$
};

\draw [red, >=stealth, <->, shorten <= 3pt, shorten >=3 pt,overlay]
 (pic cs:c) to[bend left=90] (pic cs:d);
\end{tikzpicture}
\end{center}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128