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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Bear with me as this is a multi-part question. First I'm trying figure out how to outline a matrix and not change the style of the nodes in the matrix. Maybe a better question is how to configure a node/matrix w/o changing anything within its scope.

Secondly I'd like the top of the 2nd/right matrix to be on the same y-coordinate as c.south I tried to accomplish this with positioning via right = of c.south, but it does this strange overlap thing and changes the anchor from the node origin to the node's west anchor. (The blue dots are the anchor point currently being used)


Below is the way I want it to look in the end, which I forced by using right = of c.south east, anchor = north west in the options of mtrx2 This pushes the anchors to the wrong spot (which I don't want) So is there a better way of positioning the matrix like this?

north west




\usetikzlibrary{shapes, arrows, calc, positioning}

% Define block styles
\tikzstyle{state}   = [ rounded rectangle, 
                        text centered, 
                        minimum height=3em ,
                        minimum width = 6em,
                        inner sep = 5pt
\tikzstyle{test}    = [ diamond, 
                        shape aspect=2, 
                        inner sep = 0pt,
                        text width = 7em,
                        text centered
\tikzstyle{action}  = [ rectangle, draw,
                        text width=8em,
                        inner sep = 3pt, 
                        minimum height=5em
\tikzstyle{data}    = [ trapezium, 
                        trapezium left angle=60, 
                        trapezium right angle=120pt,
                        minimum height = 6em, 
                       % text width = 5em
\tikzstyle{line}    = [ draw, -triangle 45 ]

\tikzstyle{list}  = [ rectangle, draw,
                        minimum width = 6em                      

\tikzstyle{ptr-box}  = [ rectangle, 
                        text width = 8em                      

\begin{tikzpicture}[align = flush center, font = \small]
    % Place nodes
    \matrix [column sep = 0.5em, row sep = 1.3em] (mtrx1)
    \node [state] (a) {a}; \fill[blue] (0,0) circle (2pt);\\

    \node [data] (b) {b}; \\

    \node [test] (c) {c}; \\

    \node [action] (d) {d}; \\

    \node [test] (e) {e}; \\

    \node [action] (f) {f}; \\

    \node [action] (g) {g}; \\

    \matrix [column sep = 0.5em, row sep = 1.3em, right = of c.south, draw, dashed] (mtrx2)
    \node [test] (aa) {aa}; \fill[blue] (0,0) circle (2pt);\\

    \node [test] (bb) {bb}; \fill[blue] (0,0) circle (2pt);\\

    \node [action] (cc) {cc}; \fill[blue] (0,0) circle (2pt);\\

    \node [data] (dd) {dd}; \fill[blue] (0,0) circle (2pt);\\

    \node [state] (ee) {ee}; &
    \node [state] (ff) {ff};\fill[blue] (0,0) circle (2pt);\\

    % Draw edges
    \path [draw] (a) -- (g);    
    \path [draw] (aa) -- (ff);

share|improve this question
up vote 3 down vote accepted

You can use distances to explicitly input shift amount and you can use the nodes={} to override general options. That's why matrix of nodes key is important.

\usetikzlibrary{shapes, arrows, calc, positioning,matrix}

state/.style={rounded rectangle, draw, text centered, minimum height=3em ,minimum width = 6em, inner sep = 5pt},
test/.style = {diamond, draw, shape aspect=2, inner sep = 0pt,text width = 7em,text centered},
action/.style ={rectangle, draw,text width=8em,inner sep = 3pt, minimum height=5em},
data/.style = {trapezium, draw, trapezium left angle=60, trapezium right angle=120pt, minimum height = 6em},
line/.style = {draw, -triangle 45},
list/.style = {rectangle, draw,minimum width = 6em},
ptr-box/.style = {rectangle, text width = 8em}

\begin{tikzpicture}[font = \small]
    \matrix [matrix of nodes, column sep = 0.5em, row sep = 1.3em] (mtrx1)
    |[state]| a\\
    |[data]|  b\\
    |[test]|  c\\
    |[test]|  e\\

    \matrix [matrix of nodes,column sep = 0.5em, row sep = 1.3em, 
    draw, dashed,
    nodes = {solid,red}, %<- Overrides
    right = 2cm of mtrx1-3-1.south, %How much further from right of the node...
    anchor = north west,
    ] (mtrx2)
                    &|[state]| aa\\
                    &|[test]|  bb\\
                    &|[data]|  dd\\
    |[state]|  ee   &|[state]| ff\\

    % Draw edges
    \path [draw] (mtrx1-1-1) -- (mtrx1-7-1);    
    \path [draw] (mtrx2-1-2) -- (mtrx2-5-2);


enter image description here

share|improve this answer
Implemented this in my flow-chart but I'm curious what's is going on w/ d, f, g, & cc in your edit to my example? – blitzvergnugen Sep 12 '12 at 19:59
@blitzvergnugen You have a large text box (8em) and it starts to write from the left of it. Include more text and it will be apparent or align it to the center. – percusse Sep 12 '12 at 20:09
Ah. So because the styles inside the matrix of nodes are defined by only nodes={} the align=flush center I have in the \begin{tikzpicture} isn't being applied. Is that correct? – blitzvergnugen Sep 12 '12 at 20:15
@blitzvergnugen Oh, I think I've removed it aacidentally. Sorry about that. But in general, the last setting overrides whatever comes before it. So if you use another align key for the matrix then you would be right, it would be overridden. Note however that nodes={} is an append style so it would add the properties to the existing ones. So if the overall matrix didn't have draw option we should have additionally provided it because it's not inherited from the big matrix. – percusse Sep 12 '12 at 20:24

Your Answer


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.