4

These are two separate but closely related questions.

I have the following diagram:

\documentclass[11pt,a4paper,oneside,notitlepage,tikz]{book}
\usetikzlibrary{positioning,fit,calc}
%...
\begin{document}
%...
\begin{tikzpicture}
\node (1) [draw,rectangle] {Social change};
\node (2) [draw,rectangle,below=of 1] {Mobilizing structures};
\node (3) [draw,rectangle,below left=of 2] {Opportunity and threat};
\node (4) [draw,rectangle,below right=of 2] {Framing processes};
\node (5) [draw,rectangle,below=of $(3)!0.5!(4)$] {Repertoires of contention};
\node (6) [draw,rectangle,below=of 5] {Contentious interaction};
\end{tikzpicture}
%...
\end{document}

enter image description here

  1. I don't need nodes 3 and 4 to be that far apart, i.e. I would like to have them positioned next to each other right below node 2. I understand that this undesired behaviour is precisely what the below left and below right options of the positioning library command, but not using those options would cause the two nodes to overlap.
  2. I would like for nodes 5 and 6 to be horizontally centered, just like nodes 1 and 2. Using the calc library to calculate the middle point between nodes 3 and 4 ($(3)!0.5!(4)$) doesn't do the job since they are not simmetrical and their middle point is positioned left of the central axis.

In short, I am looking for a way to horizontally position nodes relative to the central axis of the diagram.

  • 2
    something like \node (4) [draw,rectangle,below right=1 and -1 of 2] {Framing processes}; \node (5) [draw,rectangle,below=3 of 2] {Repertoires of contention};? – LaRiFaRi Jul 28 '17 at 14:07
  • Yes, something like that, provided you also change node 3's positioning into \node (3) [draw,rectangle,below left=1 and -1 of 2] {Opportunity and threat}; Incidentally, is it just my impression or the vertical distance between node 5 and the preceding two nodes is inevitably different than the standard distance when no specific value is given? – poxx Jul 28 '17 at 14:21
  • 2
    Because $(3)!0.5!(4)$ is a point. You need to replace it by $(3.south)!0.5!(4.south)$. (Or $(3.south east)!0.5!(4.south west)$. Notice the difference.) – Symbol 1 Jul 28 '17 at 15:20
  • \node (5) [draw,rectangle,below=of 3 -| 1] {Repertoires of contention}; – cfr Jul 28 '17 at 15:42
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Jul 24 '18 at 11:13
2

I think a tikz matrix is your friend.

I've given a name (m) to the matrix, so, in case you'll need to refer to your nodes, you can use m-row_number-column_number. For example, the "Social change" node is m-1-2.

If you want to increase the space between the rows, just change row sep = 2ex.

I have drawn all the nodes with the same width because they look better to me.

\documentclass[11pt,a4paper,oneside,notitlepage]{book}
\usepackage{tikz}
\usetikzlibrary{positioning,fit, matrix}
%...
\begin{document}
%...
\begin{tikzpicture}
\matrix[matrix of nodes, nodes={draw, rectangle, text width= 12em,
text height=1.5ex, text depth=0.25ex,
align = center}, row sep = 2ex,column sep = -6em] (m) {%
& Social change \\
& Mobilizing structures \\
Opportunity and threat &&
Framing processes \\
& Repertoires of contention \\
& Contentious interaction \\
};
\end{tikzpicture}
%...
\end{document}

enter image description here

0

You just need to understand how positioning library works. Every potitioning option (left, right, above left, ...) uses a particular anchor (east, west, south east,...) from the node to be placed and from the reference node. But you can change them after positioning option with a new anchor declaration.

As an example, your below left = of places 3.north east at default distance from 2.south west, but you could saybelow left = of 2.south, anchor=northwhich will place3.northat a below left distance position from2.south`.

You can also define a default distance with two components (i.e. 2mm and 1cm) where the first component will be used with horizontal and vertical positioning options (left, above, ...) and both for two components (above right).

With previous comments I hope you could understand following code.

More information about positioning library here.

\documentclass[11pt,a4paper,oneside,notitlepage]{book}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
%...
\begin{document}
%...
\begin{tikzpicture}[node distance=3mm and 1mm]
\node (1) [draw,rectangle] {Social change};
\node (2) [draw,rectangle,below=of 1] {Mobilizing structures};
\node (3) [draw,rectangle,below left=of 2.south] {Opportunity and threat};
\node (4) [draw,rectangle,below right=of 2.south] {Framing processes};
\node (5) [draw,rectangle,below left= of 4, anchor=north]  {Repertoires of contention};
\node (6) [draw,rectangle,below=of 5] {Contentious interaction};
\end{tikzpicture}
%...
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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