2

I have a multi-parts node N1, below it a node N2,I wish N1 to have same width as N2. I have set minimum width=3cm for every node but this did not have any impact on N1 node !?

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}

\begin{document}

\begin{tikzpicture}[scale=2,every node/.style={fill=blue!10,minimum width=3cm,draw}]

\node(N1)[rectangle split, rectangle split parts=3,rectangle split horizontal]
{a\nodepart{two}b\nodepart{three}c};

\node[yshift=-1cm,anchor=north](N2) at (N1.south){d};


\end{tikzpicture}

\end{document}

enter image description here

2 Answers 2

4

You could misuse the text width which does get taken in account for the node parts. However you need to subtract the inner xseps as well as the inner linewidths.

As a non-empty text width value activates a minipage-like environment for the node part texts you need something like align=center if you want to have the texts back in the center.

Note, that the property “minimum” is lost for the node parts/the whole node.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.multipart}
\tikzset{stretch split horizontal/.style={text width=(\pgfkeysvalueof{/pgf/minimum width}-
  (\pgfkeysvalueof{/pgf/rectangle split parts}-1)*\pgflinewidth)
  /(\pgfkeysvalueof{/pgf/rectangle split parts})-2*(\pgfkeysvalueof{/pgf/inner xsep})}}
\begin{document}
\begin{tikzpicture}[scale=2, every node/.style={fill=blue!10, minimum width=3cm, draw}]
\node (N1) [rectangle split, rectangle split parts=5, rectangle split horizontal,
  stretch split horizontal, align=center]
  {a \nodepart{two} b \nodepart{three} c \nodepart{four} d \nodepart{five} e};
\node[yshift=-1cm,anchor=north] (N2) at (N1.south) {d};
\end{tikzpicture}
\end{document}
4

From page 726 in pgfmanual:

When split vertically, the rectangle split will meet any minimum width requirements, but any minimum height will be ignored. Conversely when split horizontally, minimum height requirements will be met, but any minimum width will be ignored. In addition, inner sep is applied to every part that is used, so it cannot be specified independently for a particular part.

Two alternative solutions:

The first one uses a matrix of nodes instead of a multipart nodes. I know they are not the same, so some tricks are required to convert a matrix to something similar to a multipart node. In this case I've used a \vphantom option but a minimum height could also serve. And I also defined minimum width for every node in matrix as 1/3 from d node width.

The second one, draws nodes the other way, first three nodes a, b, c are drawn and second node d adjust its size with fit. In this case, fitting node content must be written with label options.

\documentclass[border=5mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning,fit}

\begin{document}

\begin{tikzpicture}[scale=2, every node/.style={fill=blue!10,minimum width=3cm,draw}]

\matrix (N1) [matrix of nodes, inner sep=0pt, nodes={fill=blue!10, minimum width=1cm, inner sep=.3333em}, column sep=-\pgflinewidth, draw=none]
{a\vphantom{d} & b & c\vphantom{d}\\};

\node[yshift=-1cm,anchor=north](N2) at (N1.south){d};

\end{tikzpicture}

\begin{tikzpicture}[scale=2, every node/.style={fill=blue!10,minimum width=1cm,draw, minimum height=5mm}]

\begin{scope}[node distance=0pt]
\node(A) {a};\node[right=of A] (B) {b};\node[right=of B] (C) {c};
\end{scope}

\node[fit=(A.north west) (C.south east), inner sep=0pt, below=1cm of B.south, label=center:d] (N2) {};


\end{tikzpicture}
\end{document}

enter image description here

1
  • Thanks @Ignasi , but I need solution with shapes.multipart library.
    – Salim Bou
    May 26, 2016 at 20:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .