7

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.

Mantas
  • 265

1 Answers1

15

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}
Torbjørn T.
  • 206,688
  • how to make bigger spaces between rectangles? :) – Mantas Mar 29 '16 at 14:11
  • @Mantas Does adding inner ysep=10pt, (or some other value) do what you want? – Torbjørn T. Mar 29 '16 at 14:15
  • No :) I have no spaces between rectangles now. Its more like width or something :) – Mantas Mar 29 '16 at 14:15
  • inner sep isn't doing the job :/ Still no spaces between rectangles... – Mantas Mar 29 '16 at 14:16
  • @Mantas I don't understand, do you want a gap between the red and the blue part? Your last comment I don't understand at all. – Torbjørn T. Mar 29 '16 at 14:19
  • I need gap between rectangle 1 and rectangle 2 . Not between parts :) – Mantas Mar 29 '16 at 14:19
  • @Mantas Well, I cannot know how you positioned the second node (rectangle 2), so all I can say is choose a different coordinate, further away from the first node. I'd recommend asking a new question about it though. – Torbjørn T. Mar 29 '16 at 14:22
  • @TorbjørnT. Could the colors be side by side as well? – Faceb Faceb Aug 12 '17 at 13:38
  • @FacebFaceb Add rectangle split horizontal after rectangle split in the state style. (Cf. the description of rectangle split in the manual, chapter 67.6 Shapes with multiple parts.) – Torbjørn T. Aug 12 '17 at 14:19
  • @TorbjørnT. And could the splitted rectangles have gradients or pictures in it as well as in https://tex.stackexchange.com/questions/215895/color-gradient-in-tikzpicture-from-top-to-bottom-corner and https://tex.stackexchange.com/questions/219356/how-to-create-a-rectangle-filled-with-image-using-tikz respectively? – Faceb Faceb Aug 12 '17 at 15:40
  • @FacebFaceb Not entirely sure, I'd suggest you ask a new question about that. – Torbjørn T. Aug 12 '17 at 15:44