1

So I have made a split rectangle using Torbjørn T.'s answer in How to split tikz rectangle by half with different colors and text lines.

But could I use gradient (Color gradient in tikzpicture from top to bottom corner) in the upperhalf and pictures (How to create a rectangle filled with image using TikZ?) in the lowerhalf as fills as well?

5

enter image description here

is this what you like to have? sorry, the question is not clear to me ...

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shapes.multipart}

\begin{document}
\begin{tikzpicture}[
box/.style={
       rectangle split, rectangle split parts=2,
       draw=black, thick, rounded corners,
       left color=blue, right color=blue!20!white,
       text width=3cm, align= center}
                    ]
\node [box]
       {\nodepart{one} text text
        \nodepart{two} text};
\end{tikzpicture}
\end{document}

or something like this:

enter image description here

\documentclass[tikz,border=3mm] {standalone}
    \usetikzlibrary{arrows,fadings, positioning, shapes.multipart}
    \usepackage{siunitx}
\begin{document}
    \begin{tikzpicture}[
    node distance=3mm,
box/.style args = {#1/#2/#3}{
        rectangle split, rectangle split parts=2,
        draw=black, thick, rounded corners,
        text width=3cm, align=center,
        postaction={path fading =#1,
                    fading angle=#2,
                    fill=#3}}
                        ]
\node (n1) [box=north/45/blue] {text1 \nodepart{two} text 2};
\node (n2) [box=south/-45/orange,
            below=of n1] {text1 \nodepart{two} text 2};
    \end{tikzpicture}
\end{document}

edit (1): regarding to edit of question: in the multi part shapes the gradient coloring and fading separately for each shape parts is not possible to do with known shape's options (your question seems to be new feature request for multi part shapes).

edit (2): as workaround the gradient colors on the background layer separately for each node part in case, can be drawn:

enter image description here

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shapes.multipart}

\begin{document}
\begin{tikzpicture}[
box/.style args = {#1/#2}{
       rectangle split, 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.one west) 
    [rounded corners] |- (\tikzlastnode.north) -| (\tikzlastnode.one east) 
    [sharp corners]   |- (\tikzlastnode.one split) -| cycle;
        \fill[left color=#2, right color=#2!20!white]
    (\tikzlastnode.two west) 
    [rounded corners] |- (\tikzlastnode.south) -| (\tikzlastnode.two east)  
    [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} longer, two lines text in part 1
        \nodepart{two} text 2};
\end{tikzpicture}
\end{document}

where append after command={\pgfextra ...} is used to fill each shape's part separately.

  • Does ?? mean : Yes you can use gradient as fill ? – marsupilam Aug 12 '17 at 17:12
  • actually mean: is this what OP like to have :) i'm not sure if i understand what is desired result. corrected in answer :) – Zarko Aug 12 '17 at 17:14
  • thanks for your answer! sorry, my question is a little unclear, I'll edit the question :) – Faceb Faceb Aug 12 '17 at 19:54
  • you can solve your problem with drawing stack of two rectangles with solution of the my first solution and then clip corners to round shape. – Zarko Aug 12 '17 at 20:28
  • @Zarko Could you please explain \draw[thick, % node part one left color=#1, right color=#1!20!white] (\ppbb.west) [rounded corners] |- (\ppbb.north) -| (\ppbb.east) [sharp corners] |- (\ppbb.north |- \ppbb.west) -| cycle; \draw[thick, % node part two left color=#2, right color=#2!20!white] (\ppbb.west) [rounded corners] |- (\ppbb.south) -| (\ppbb.east) [sharp corners] |- (\ppbb.south |- \ppbb.west) -| cycle;? – Faceb Faceb Aug 13 '17 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.