TikZ Styles – How to Split TikZ Rectangle by Half with Different Colors and Text Lines

tikz-styles

So I have tkiz style:

\tikzset{
state/.style={
       rectangle,
       rounded corners,
       draw=black, very thick,
       minimum height=2em,
       inner sep=2pt,
       text centered,
       },

How I can split this rectangle to two parts, with different colors, like:

|----|
| red|
|----|
|blue|
|____|

And how I could write text in different lines, but in same part. Or I should another command?

Thanks in advance.

Best Answer

The rectangle split shape from the shapes.multipart library can do this.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\tikzset{
state/.style={
       rectangle split,
       rectangle split parts=2,
       rectangle split part fill={red!30,blue!20},
       rounded corners,
       draw=black, very thick,
       minimum height=2em,
       text width=3cm,
       inner sep=2pt,
       text centered,
       }
}
\begin{document}
\begin{tikzpicture}
\node [state] {text\\txet \nodepart{two} blue background \\ here};
\end{tikzpicture}
\end{document}
Related Question