2

I am using following solution How to split tikz rectangle by half with different colors and text lines. On top of this solution is it possible to split a row into two and color it differently?

@Torbjørn T. solution from the linked answer:

\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}

wanted output:

|-----|-------|
| red | white |
|-----|-------|
|    blue     |
|_____________|

enter image description here

alper
  • 1,389
  • 2
    Please don't just post code fragments. Always make a compilable minimal working example as starting point. – samcarter_is_at_topanswers.xyz Jan 06 '23 at 14:42
  • 1
    Sorry fixed I try to add quote to code piece which messed up its format – alper Jan 06 '23 at 14:49
  • Here are 2 threads that seem to deal with this question: 1 https://tex.stackexchange.com/questions/152292/split-a-node-into-3-parts and https://tex.stackexchange.com/questions/651710/tikz-split-rectangle-into-2 link number one is the most suitable IMO – anis Jan 06 '23 at 14:49
  • @anis first linked thread does not use rectangle split – alper Jan 06 '23 at 14:53
  • @alper is using rectangle split that crucial for you? – anis Jan 06 '23 at 15:00
  • @anis yes sir its easier to coordinate arrows starting points on rectangle split when there are multiple rows inside rectangle – alper Jan 06 '23 at 17:27

2 Answers2

3

Here is my adaptation of this solution: How create circle node in Tikz with T from lines inside? T made split node to 3 sectors

I just added rectangles to fill the space inside the node. enter image description here

\documentclass[11pt]{article}
\usepackage{tikz}

\begin{document}

\tikzset{sectors/.style n args={6}{%
        rectangle,
        draw,
        minimum width=#4,
        minimum height=#5,
        append after command={%
            \pgfextra{ %
                \draw (\tikzlastnode.center) -- (\tikzlastnode.south) ;
                \draw (\tikzlastnode.west)   -- (\tikzlastnode.east) ;
                \draw[fill = blue] (\tikzlastnode.west) rectangle (\tikzlastnode.north east);  
                \path (\tikzlastnode.center) -- node[#6] {#1} (\tikzlastnode.north); 

                \draw[fill = cyan] (\tikzlastnode.center) rectangle (\tikzlastnode.south west);  
                \path (\tikzlastnode.center) -- node[#6] {#2} (\tikzlastnode.south west); 

                \draw[fill = green] (\tikzlastnode.center) rectangle (\tikzlastnode.south east);  
                \path (\tikzlastnode.center) -- node[#6] {#3} (\tikzlastnode.south east);
             } }}}

\begin{tikzpicture}[ultra thick]
\node [sectors={1}{2}{3}{5cm}{5cm}{font=\Huge\bfseries,text=red}]  (c)  {};
\end{tikzpicture}

\end{document}

anis
  • 1,510
  • 5
  • 13
2

Similar to @anis answer, but code reproduce in question showed image:

enter image description here

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,
                positioning}

\begin{document} \tikzset{ sectors/.style n args={8}{minimum width=#1, minimum height=#2, text depth=0.25ex, outer sep=0pt, append after command={\pgfextra{\let\LN\tikzlastnode \draw[fill=#3] (\LN.west) -| (\LN.north) {[rounded corners=3mm] -- (\LN.north west)} |- cycle; % \draw[fill=#5] (\LN.north) |- (\LN.east) {[rounded corners=3mm] -- (\LN.north east)} -- cycle; % \draw[fill=#7] (\LN.west) {[rounded corners=3mm] |- (\LN.south east)} |- cycle; \path (\LN.center) -- node[align=center] {#4} (\LN.north west) (\LN.center) -- node[align=center] {#6} (\LN.north east) (\LN.center) -- node[align=center] {#8} (\LN.south); } } } } \begin{tikzpicture} \node [sectors= {32mm}{24mm} {red!30}{text\ text} {white}{Disk} {blue!30}{blue bacground\ here}] {}; \end{tikzpicture}

\end{document}

However, I suspect that you looking for general building blocks (BB), by which you can to compose any blocks structure:

  • Is this is a case, you should be aware that splitting of nodes to subnodes is very hard task.
  • Far more simple is connect nodes (BB), tight to each other, in desired connections.
  • In this is drawing further simpler, if nodes shapes are rectangles with sharp corners (than is sufficient to define only one BB),
  • For further/better help, please show us an example of structure(s) which you like to draw.
  • Below is an example of composition with simple building blocks of rectangle shape:

enter image description here

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document} \tikzset{ node distance = 0pt, BB/.style args={#1/#2/#3}{% Building Box, options draw, semithick, font=\small\linespread{0.84}\selectfont, align=center, minimum width=#1, minimum height=#2, text depth=0.25ex, fill=#3, outer sep=0pt} } % end of tikzset \begin{tikzpicture} \node (L1) [BB=32mm/8mm/teal!30] {basic layer}; \node (L2) [BB=32mm/8mm/yellow!30, above=of L1] {second layer}; \node (L31) [BB=16mm/12mm/red!30, above right=of L2.north west] {third\ level\ first}; \node (L32) [BB=16mm/12mm/orange!30, right=of L31] {third\ level\ second}; \end{tikzpicture}

\end{document}

Zarko
  • 296,517