9

I have that issue when try to fill a split node with two different colors. After using rectangle split part fill={red,blue} as an node argument the drop shadow overlap the node because I don't use the fill=color argument.

How can I avoid this issue?enter image description here

Full code:

%USER INTERFACE CLASS DIAGRAMM
\documentclass{minimal}
\usepackage[a4paper,margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usepackage{xcolor}

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{comment}
:Title: User Interface Class diagram
\end{comment}

%COLORS
\definecolor{Recessive}{RGB}{77, 87, 98}    %BLUE
\definecolor{Dominant}{RGB}{229, 126, 49}   %ORANGE

%WRITE CODE
\def\title#1{Klassendiagramm:\smallbreak \fontsize{14}{14}\textbf{\texttt{#1}}}
\def\code#1{\texttt{#1}\newline}
\def\codeEnd#1{\texttt{#1}}

\usetikzlibrary{positioning,shapes,shadows,arrows}

\begin{document}
\tikzstyle{abstract}=[rectangle, draw=black, rounded corners, fill=Recessive, drop shadow,
    text centered, anchor=north, text=white, text width=3cm]
\tikzstyle{comment}=[rectangle, draw=black, rounded corners,
    text centered, anchor=north, text=white, text width=3cm]
\tikzstyle{myarrow}=[->, >=open triangle 90, thick]
\tikzstyle{line}=[-, thick]

\begin{center}
\begin{tikzpicture}[node distance=3.8cm]
\node [text width=4cm] at (-7,0) {\title{Interface}};

\node (Client) [abstract, rectangle split, rectangle split parts=2]
    {
        \textbf{Client}
        \nodepart{second}Schnittstellen
    };

%NODE LEVEL 01
\node (Level01) [text width=4cm, below=2.5cm of Client] {}; %LEVEL 01

%CONSOLE    
\node (Console) [abstract, rectangle split, rectangle split parts=2, left=of Level01]
    {
        \textbf{Console}
        \nodepart{second}Benutzereingaben
    };   
\node (Console_Comment) [comment, rectangle split, rectangle split parts=2, rectangle split part fill={red,blue}, drop shadow, below=0.2cm of Console, text justified]
    {
        \textbf{Funktionen}
        \nodepart{second}\code{Scripts} \code{Format} \code{getScripts} \codeEnd{getCode}
    };
\end{tikzpicture}
\end{center}
\end{document}
7

in year 2010 Mark Wibrow suggested me (for the similar problem) the hack which enable correct dropping show at custom fill of multi part node shape. using it in your (now really) mwe is:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning,
                shadows,
                shapes.multipart}
\pgfdeclarelayer{foreground}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main,foreground}
\makeatletter
\def\tikz@extra@preaction#1{% hackery which enable preactions 
                            % in multi-part node on a different layer
                            % suggested by Mark Wibrow on c.t.t. (2010)
  {%
    \pgfsys@beginscope%
      \setbox\tikz@figbox=\box\voidb@x%
      \begingroup\tikzset{#1}\expandafter\endgroup%
      \expandafter\def\expandafter\tikz@preaction@layer
\expandafter{\tikz@preaction@layer}%
      \ifx\tikz@preaction@layer\pgfutil@empty%
      \path[#1];% do extra path
      \else%
      \begin{pgfonlayer}{\tikz@preaction@layer}%
      \path[#1];%
      \end{pgfonlayer}
      \fi%
      \pgfsyssoftpath@setcurrentpath\tikz@actions@path% restore
      \tikz@restorepathsize%
    \pgfsys@endscope%
  }%
}
\let\tikz@preaction@layer=\pgfutil@empty
\tikzset{preaction layer/.store in=\tikz@preaction@layer}
\makeatother

\tikzset{% style for multi-part node with dropped shadow on background layer
mpv/.style = {% multi part vertical (node)
    rectangle split,
    rectangle split parts=2,
    rectangle split part fill={#1}, % <-- enable different fill for each node part
    draw, rounded corners, text width=3cm,
    align=center, text=white,
  preaction layer=background,       % <-- prepare layer for drop shadow
    drop shadow}, 
        }

\begin{document}
 \begin{tikzpicture}[node distance = 2mm]
% CONSOLE
\node (n1) [mpv=black!70]
    {
        \textbf{Console}
        \nodepart{two}  Benutzereingaben
    };
% FUNKTIONEN
\node (n2) [mpv={red,blue}, below=of n1]
    {
        \textbf{Funktionen}
        \nodepart[align=left]{two}  \verb+Scripts+ \\
                                    \verb+Format+ \\
                                    \verb+getScripts+ \\
                                    \verb+getCode+
    };
\end{tikzpicture}
\end{document}

enter image description here

you can change node names to what you use in your mwe. for the text in the second part of the node "Funktionen" are used verb environments instead yours \code{...} commands. you can use them, if you more liked them.

as you can see, that after preparation of separate layer for drop shadow you only need to add preaction layer=background to multi-part node style definition. the multi-part node style is common for bot nodes, however, if you more prefer to have different node's style for each node, you can define them as follows:

\tikzset{% 
mpv/.style = {% multi part vertical (node)
    rectangle split,
    rectangle split parts=2,
    draw, rounded corners, text width=3cm,
    align=center, text=white,
  preaction layer=background, 
    drop shadow}, 
abstract/.style = {mpv, fill=black!30},
 comment/.style = {mpv, rectangle split part fill={red,blue}},
        }

and then use them similarly as in yours mwe:

\node (<node name>) [abstract] {....};
\node (<node name>) [comment, below=of n1] {...};
  • Uhh, that's nasty. But it works fine. I implemented with a function. thanks for your help. :-) – Mar Tin Dec 25 '18 at 13:23
  • 1
    @Nusserdt, what is nasty? the code is written in spirit of tikz, since Mark is one of its coauthors ... its use is very simply, clear and intuitive. – Zarko Dec 25 '18 at 15:45
6

There must certainly be a better solution, but here's a quick hack: Draw the node twice, the first time with the shadow and the second time without.

capture

%USER INTERFACE CLASS DIAGRAMM
\documentclass{minimal}
\usepackage[a4paper,margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usepackage{xcolor}

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{comment}
:Title: User Interface Class diagram
\end{comment}

%COLORS
\definecolor{Recessive}{RGB}{77, 87, 98}    %BLUE
\definecolor{Dominant}{RGB}{229, 126, 49}   %ORANGE

%WRITE CODE
\def\title#1{Klassendiagramm:\smallbreak \fontsize{14}{14}\textbf{\texttt{#1}}}
\def\code#1{\texttt{#1}\newline}
\def\codeEnd#1{\texttt{#1}}

\usetikzlibrary{positioning,shapes,shadows,arrows}

\begin{document}
\tikzstyle{abstract}=[rectangle, draw=black, rounded corners, fill=Recessive, drop shadow,text centered, anchor=north, text=white, text width=3cm]
\tikzstyle{comment}=[rectangle, draw=black, rounded corners, text centered, anchor=north, text=white, text width=3cm]
\tikzstyle{myarrow}=[->, >=open triangle 90, thick]
\tikzstyle{line}=[-, thick]

\begin{center}
\begin{tikzpicture}[node distance=3.8cm]
\node [text width=4cm] at (-7,0) {\title{Interface}};

\node (Client) [abstract, rectangle split, rectangle split parts=2]
    {
        \textbf{Client}
        \nodepart{second}Schnittstellen
    };

%NODE LEVEL 01
\node (Level01) [text width=4cm, below=2.5cm of Client] {}; %LEVEL 01

%CONSOLE    
\node (Console) [abstract, rectangle split, rectangle split parts=2, left=of Level01]
    {
        \textbf{Console}
        \nodepart{second}Benutzereingaben
    };  
\begin{scope}

\end{scope}     
\node (Console_Comment) [comment, rectangle split, rectangle split parts=2, drop shadow, below=0.2cm of Console, text justified]
    {
        \textbf{Funktionen}
        \nodepart{second}\code{Scripts} \code{Format} \code{getScripts} \codeEnd{getCode}
    };
    \node (Console_Comment) [comment, rectangle split, rectangle split parts=2, rectangle split part fill={red,blue}, below=0.2cm of Console, text justified]
    {
        \textbf{Funktionen}
        \nodepart{second}\code{Scripts} \code{Format} \code{getScripts} \codeEnd{getCode}
    };
\end{tikzpicture}
\end{center}
\end{document}
4

How does casting shadows work? A path gets stored and reused (while shifted). You could just do the same on the background layer. My answer uses the use path trick.

%USER INTERFACE CLASS DIAGRAMM
\documentclass{minimal}
\usepackage[a4paper,margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usepackage{xcolor}

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{comment}
:Title: User Interface Class diagram
\end{comment}

%COLORS
\definecolor{Recessive}{RGB}{77, 87, 98}    %BLUE
\definecolor{Dominant}{RGB}{229, 126, 49}   %ORANGE

%WRITE CODE
\def\title#1{Klassendiagramm:\smallbreak \fontsize{14}{14}\textbf{\texttt{#1}}}
\def\code#1{\texttt{#1}\newline}
\def\codeEnd#1{\texttt{#1}}

\usetikzlibrary{positioning,shapes,shadows,arrows,backgrounds}
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother

\begin{document}
\tikzset{abstract/.style={rectangle, draw=black, rounded corners, fill=Recessive, drop shadow,
    text centered, anchor=north, text=white, text width=3cm},
comment/.style={rectangle, draw=black, rounded corners,
    text centered, anchor=north, text=white, text width=3cm},
myarrow/.style={->, >=open triangle 90, thick},
line/.style={-, thick}}

\begin{center}
\begin{tikzpicture}[node distance=3.8cm]
\node [text width=4cm] at (-7,0) {\title{Interface}};

\node (Client) [abstract, rectangle split, rectangle split parts=2]
    {
        \textbf{Client}
        \nodepart{second}Schnittstellen
    };

%NODE LEVEL 01
\node (Level01) [text width=4cm, below=2.5cm of Client] {}; %LEVEL 01

%CONSOLE    
\node (Console) [abstract, rectangle split, rectangle split parts=2, left=of Level01]
    {
        \textbf{Console}
        \nodepart{second}Benutzereingaben
    };   
\node (Console_Comment) 
[comment, rectangle split, rectangle split parts=2, rectangle split part fill={red,blue}, 
save path=\tmpath, below=0.2cm of Console, text justified]
    {
        \textbf{Funktionen}
        \nodepart{second}\code{Scripts} \code{Format} \code{getScripts} \codeEnd{getCode}
    };
\begin{scope}[on background layer]  
\fill[black!50,opacity=0.5,
use path=\tmpath,transform canvas={xshift=0.5ex,yshift=-0.5ex}];
\end{scope}
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

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.