1

As a follow-up question of Use gradient or picture as fill in split rectangle? and with many thanks to Zarko's answer, I tried to modify their code to split the rectangle side by side.

The following code:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds, fit, positioning, shapes.multipart}
\newcommand\ppbb{path picture bounding box}

\begin{document}
\begin{tikzpicture}[
box/.style args = {#1/#2}{
   rectangle split, rectangle split horizontal, rectangle split parts=2,
   rounded corners,
   text width=3cm, align=center,
   path picture={   \begin{scope}[on background layer]
                    \draw[thick, % node part one
                          left color=#1, right color=#1!20!white]
        (\ppbb.south) [rounded corners] -| (\ppbb.west) |- (\ppbb.north) [sharp corners] -| (\ppbb.north |- \ppbb.east) -| cycle;
                    \draw[thick, % node part two
                          left color=#2, right color=#2!20!white]
        (\ppbb.south) [rounded corners] -| (\ppbb.east) |- (\ppbb.north) [sharp corners] -| (\ppbb.south |- \ppbb.west) -| cycle;
                    \end{scope}
                }%end of path picture
        }
                ]
\node [box=blue/red]
   {\nodepart{one} text \\ text \\ text \\ text
    \nodepart{two} text \\ text \\ text \\ text};
\end{tikzpicture}
\end{document}

produces the following figure: enter image description here

However, I do not know how to fix the upper part (I would like the upper part to be the same as the bottom part) as I do not understand this part of the code:

\draw[thick, % node part one
                      left color=#1, right color=#1!20!white]
    (\ppbb.south) [rounded corners] -| (\ppbb.west) |- (\ppbb.north) [sharp corners] -| (\ppbb.north |- \ppbb.east) -| cycle;
                \draw[thick, % node part two
                      left color=#2, right color=#2!20!white]
    (\ppbb.south) [rounded corners] -| (\ppbb.east) |- (\ppbb.north) [sharp corners] -| (\ppbb.south |- \ppbb.west) -| cycle;

Could someone please explain?

1 Answer 1

1

your mwe is very close to right solution :-). you only need to correct draw fill borders. in this is helpful image on page 729 in "tikz \& pgf manula, v 3.0.3a".

based on my answer in addendum:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds, fit, positioning, shapes.multipart}
\newcommand\ppbb{path picture bounding box}

\begin{document}
\begin{tikzpicture}[
box/.style args = {#1/#2}{
        rectangle split, rectangle split horizontal, rectangle split parts=2,
        rounded corners,
        text width=3cm, align=center,
        draw,  thick,
        append after command={\pgfextra
            \fill[left color=#1, right color=#1!20!white]
        (\tikzlastnode.south)
        [rounded corners] -| (\tikzlastnode.west) |- (\tikzlastnode.one north)
        [sharp corners]   -| (\tikzlastnode.one split) |- cycle;
            \fill[left color=#2, right color=#2!20!white]
        (\tikzlastnode.two south)
        [rounded corners] -| (\tikzlastnode.east) |- (\tikzlastnode.north)
        [sharp corners]   -| (\tikzlastnode.one split) |- cycle;
                                        \endpgfextra}% end of the append after command
                            }% end of the box style definition
                    ]
\node [box=blue/red]
   {\nodepart{one} text \\ text \\ text \\ text
    \nodepart{two} text \\ text \\ text \\ text};
\end{tikzpicture}
\end{document}

enter image description here

3
  • @FacebFaceb, here is habit that gratitude is expressed by voting for answer even accept it (if it solve your problem in the best way) :-)
    – Zarko
    Aug 13, 2017 at 18:51
  • Ok I accepted your answer! Aug 13, 2017 at 19:05
  • I used this in my work, great job! Dec 12, 2017 at 15:17

You must log in to answer this question.

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