Add baseline=(current bounding box.center)
as option to the tikzpicture
and \tikz
command. This places the baseline of the diagrams at its center and will cause a vertical alignment with the other baselines(!).
However, if you want to align it with the vertical center of the text, i.e. the center of "is", which looks most likely better, use
baseline={([yshift=-1ex]current bounding box.center)}
instead. Adjust the value for your liking. Maybe .8ex
might be better (an uppercase letter is about 1.6ex).
\documentclass{article}
\usepackage{tikz}
\begin{document}
This is a
\begin{tikzpicture}[baseline={([yshift=-.8ex]current bounding box.center)}]
\node[draw, rectangle, align=left] {%
And here \\[.3em]
is
\tikz [baseline={([yshift=-.8ex]current bounding box.center)}]
\node[draw, rectangle, align=center] {a \\ nested};
};
\end{tikzpicture}
one.
\end{document}
Some other hints:
In general you can use \raisebox{<length>}{<content>}
to raise or lower some material. You can use then \height
, \depth
, \width
and \totalheight
to refer to the original dimensions of the content. Use \dimexpr
to do math:
\raisebox{\dimexpr-.5\height+.5\depth+.8ex\relax}{<content>}
There is also \vcenter{...}
which will center things vertical, but it is intended to be used in mathmode.
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
and positioning
but I think you need to avoid the old way to place the nodes.
Explanation : Instead of below left of=top
you need to write below left= of top
.
/tikz/above left (no value)
Does the same as anchor=south east. Note
that giving both above and left options does not have the same effect
as above left, rather only the last left “wins.” Actually, this option
also takes an ⟨offset⟩ parameter, but using this parameter without
using the positioning library is deprecated. (The positioning library
changes the meaning of this parameter to something more sensible.)
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
with
\path (A) -- node [below= 3cm] {$\bot$} (B);
My solution
\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}[node distance=3cm,on grid]
\draw[help lines] (-6,-9) grid (6,1);
\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\}};
\path (node1node2) -- node (bot) [text=red,below=3cm] {$\bot$} (node4node3);
\draw (top) edge (node1)
edge (node2)
edge (node3)
edge (node4);
\draw (node1node2) edge (bot)
edge (node1)
edge (node2);
\draw (node4node3) edge (bot)
edge (node3)
edge (node4);
\end{tikzpicture}
\end{center}
\end{document}
With the next code the graph is symmetric
\begin{center}
\begin{tikzpicture}[node distance=3cm,on grid]
...
\node (node4node3) [below left= of node4] {\{node3, node4\}};
...
\end{tikzpicture}
\end{center}
without 'on gridand with the default
node distance`
\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[help lines] (-6,-9) grid (6,1);
\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\}};
\path (node1node2) -- node (bot) [text=red,below=1cm] {$\bot$} (node4node3);
\draw (top) edge (node1)
edge (node2)
edge (node3)
edge (node4);
\draw (node1node2) edge (bot)
edge (node1)
edge (node2);
\draw (node4node3) edge (bot)
edge (node3)
edge (node4);
\end{tikzpicture}
\end{center}
\end{document}
Remarks, complements
To place a node between two others nodes there is two methods :
1) \begin{tikzpicture}
\node (a) {a} ;
\node (b) at (4,2) {b};
\path (a) -- node {m} (b);
% or \path (a) -- (b) node[midway]{m};
% or pos =.5 instead of midway
\end{tikzpicture}
2) \begin{tikzpicture} % with calc library
\node (a) {a} ;
\node (b) at (4,2) {b};
\node at ($(a)!0.5!(b)$) {m};
\end{tikzpicture}
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)
\begin{tikzpicture}
\node (a) {a} ;
\node (b) at (8,0) {b};
\path (a) -- (b) node[pos=.25]{c} node[pos=.5]{d} node[pos=.75]{e};
\end{tikzpicture}
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 cm
If you need to scale the picture, it's interesting to use the calc library and to avoid positioning. Example :
\node at ($(a)!0.5!(b)+(0,-1)$) {m};
With this method, you can use scale=2
Best Answer
You could use the
positioning
library and then use theleft=of <node identifier>
for positioning the node containing the array; I added some more files to the array to see the effect:More generally (as Caramdir has suggested), you can use
left=of current bounding box.center
: