I want to create a node below 2 other node but place it exactly in the middle of the two nodes. Here's what I have so far…
\documentclass[12pt]{article}
\thispagestyle{empty}
\usepackage{tikz}
\usepackage{amsfonts}
\begin{document}
\begin{center}
\begin{tikzpicture}[node distance=3cm]
\node (top) {$\top$};
\node (node1) [below left of=top] {\{node1\}};
\node (node2) [left of=node1] {\{node2\}};
\node (node3) [below right of=top] {\{node3\}};
\node (node4)[right of=node3] {\{node4\}};
\node (node1node2) [below right of=node2] {\{node2 , node1\}};
\node (node4node3) [below right of=node3] {\{node3, node4\}};
\node (bot) [below left of = node4node3] {$\bot$};
\draw (top) -- (node1);
\draw (top) -- (node2);
\draw (top) -- (node3);
\draw (top) -- (node4);
\draw (node4) -- (node4node3);
\draw (node3) -- (node4node3);
\draw (node2) -- (node1node2);
\draw (node1) -- (node1node2);
\draw (node1node2) -- (bot);
\draw (node4node3) -- (bot);
\end{tikzpicture}
\end{center}
\end{document}
The node "bot" is almost but not exactly in the middle of nodes "node1node2" and "node3node4". It should be at the bottom of the picture at the center
Best Answer
Firstly, I'm not sure of what you want. I understand that you want the last node "bot" in the middle of (node1node2) and (node4node3) but before I would like to know if you want a symmetric graph.
In this case you need to write
\node (node4node3) [below left of=node4]
instead of\node (node4node3) [below right of=node3]
.If the graph is symmetric then the middle is below (top) and there is no problem to place (bot).
If the graph is not symmetric first you can use Peter's method with the libraries
calc
andpositioning
but I think you need to avoid the old way to place the nodes. Explanation : Instead ofbelow left of=top
you need to writebelow left= of top
.The result is not the same because the node distance is not the distance between the centers of the nodes. If you want the same result, you need to use the option
on grid
.To get the middle of two nodes, you can avoid the library
calc
withMy solution
With the next code the graph is symmetric
without 'on grid
and with the default
node distance`Remarks, complements
To place a node between two others nodes there is two methods :
The choice of the method depends of the way used to create the graphs ( with absolute coordinates, with the positioning library or without, with the possibility to scale , if you need to add several nodes)
If you need to place a node below the middle. It's interesting to use the positioning library except if you need to scale the picture.
Without the positioning library, 5 signifies 5 pt in
\path (a) -- node[below=5] {m} (b);
but with the positioning library 5 signifies 5 cmIf you need to scale the picture, it's interesting to use the calc library and to avoid positioning. Example :
With this method, you can use
scale=2