[Tex/LaTex] Split rectangle with gaps

tikz-pgftikz-shape

The rectangle split from the shapes.multipart can produce rectangles tightly stacked.

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.multipart}

\begin{document}
\begin{tikzpicture}
  \node[
    draw, fill=lightgray,
    rounded corners,
    rectangle split, rectangle split parts=3
  ] {
    first part
    \nodepart{two}second part
    \nodepart{three}\ldots
  };
\end{tikzpicture}
\end{document}

no gaps

But I would like to have gaps in between the parts like this. Rounded corners were added for emphasis.

gaps

All of them should be as wide as the widest of them, text with should not be fixed. They should be able to contain complex matter, like listings. Are multipart shapes the right approach? Would it be appropriate to define a custom shape?

How can rectangular nodes be stacked?

Best Answer

I think this code, using tcolorbox and eqparbox should help. Eqparbox defines tagged boxes, so that all boxes with the same tag eventually all have the width of the widest of them (requires two compilations):

\documentclass{article}

\usepackage{tcolorbox}
\usepackage{eqparbox}

\begin{document}

\begin{center}
  \tcbox{\eqmakebox[P]{First Part}}

  \tcbox{\eqmakebox[P]{Second Part}}

  \tcbox{\eqmakebox[P]{$ \dots $}}
\end{center}

\end{document} 

enter image description here