个性化矩形节点 tikz

个性化矩形节点 tikz

我要做的是重现这个例子: 在此处输入图片描述

我的代码如下(有点长,抱歉):

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1]

\tikzset{
noeudA/.style={
  rectangle,
  inner sep=0pt,
  text width=25mm,
  align=center,
  draw=black,
  fill=green!30,
  minimum height = 10mm
  },
noeudB/.style={
  rectangle,
  inner sep=0pt,
  text width=25mm,
  align=center,
  draw=black,
  fill=green!20,
  minimum height = 10mm
  },
noeudC/.style={
  rectangle,
  inner sep=0pt,
  text width=20mm,
  align=center,
  draw=black,
  fill=green!10,
  minimum height = 12mm
  },
noeudD/.style={
  rectangle,
  inner sep=0pt,
  text width=20mm,
  align=center,
  draw=black,
  fill=blue!10,
  minimum height = 10mm
  },
feuille/.style={
  rectangle,
  inner sep=0pt,
  text width=20mm,
  align=center,
  draw=black,
  fill=blue!10,
  minimum height = 10mm
  },
segment/.style={
 very thick
 }
}

\def\DistanceInterFeuilles{1.3}

\def\NiveauA{0}
\def\NiveauB{-2}
\def\NiveauC{-4}
\def\NiveauD{-6}

% Noeuds (MODIFIABLES : Styles et Coefficients d'InterFeuilles)
\node[noeudA] (R) at (0,{\NiveauA}) {SCR};

\node[noeudB] (Ra) at (-4,{\NiveauB}) {Ajustement};
\node[noeudB] (Rb) at (0,{\NiveauB}) {BSCR};
\node[noeudB] (Rc) at (4,{\NiveauB}) {Opérationnel};

\node[noeudC] (Rba) at (-7.5, {\NiveauC}) {Marché};
\node[noeudC] (Rbb) at (-4.5, {\NiveauC}) {Santé};
\node[noeudC] (Rbc) at (-1.5, {\NiveauC}) {Contre-partie};
\node[noeudC] (Rbd) at (1.5, {\NiveauC}) {Vie};
\node[noeudC] (Rbe) at (4.5, {\NiveauC}) {Non-vie};
\node[noeudC] (Rbf) at (7.5, {\NiveauC}) {Actifs incorporels};

% Noeud Marché
\node[noeudD] (Rbaa) at (-8,{\NiveauD - (1)*\DistanceInterFeuilles}) {Taux d'intérêt};
\node[noeudD] (Rbab) at (-8,{\NiveauD - (2)*\DistanceInterFeuilles}) {Action};
\node[noeudD] (Rbac) at (-8,{\NiveauD - (3)*\DistanceInterFeuilles}) {Immobilier};
\node[noeudD] (Rbad) at (-8,{\NiveauD - (4)*\DistanceInterFeuilles}) {Spread};
\node[noeudD] (Rbae) at (-8,{\NiveauD - (5)*\DistanceInterFeuilles}) {Change};
\node[noeudD] (Rbaf) at (-8,{\NiveauD - (6)*\DistanceInterFeuilles}) {Concen\-tration};
\node[noeudD] (Rbag) at (-8,{\NiveauD - (7)*\DistanceInterFeuilles}) {Illiquidité};

% Noeud Santé
\node[noeudD] (Rbba) at (-5.5,{\NiveauD}) {SLT};
\node[noeudD] (Rbbaa) at (-5.5, {\NiveauD - (1)*\DistanceInterFeuilles -0.5}) {Mortalité};
\node[noeudD] (Rbbab) at (-5.5, {\NiveauD - (2)*\DistanceInterFeuilles -0.5}) {Longévité};
\node[noeudD] (Rbbac) at (-5.5, {\NiveauD - (3)*\DistanceInterFeuilles -0.5}) {Incapacité Invalidité};
\node[noeudD] (Rbbad) at (-5.5, {\NiveauD - (4)*\DistanceInterFeuilles -0.5}) {Rachat};
\node[noeudD] (Rbbae) at (-5.5,{\NiveauD - (5)*\DistanceInterFeuilles -0.5} ) {Dépenses };
\node[noeudD] (Rbbaf) at (-5.5, {\NiveauD - (6)*\DistanceInterFeuilles -0.5}) {Révision};
\node[noeudD] (Rbbb) at (-3.25,{\NiveauD}) {Catastrophe};
\node[noeudD] (Rbbc) at (-1, {\NiveauD}) {NSLT};
\node[noeudD] (Rbbca) at (-1, {\NiveauD - (1)*\DistanceInterFeuilles -0.5}) {Prime et réserve};
\node[noeudD] (Rbbcb) at (-1, {\NiveauD - (2)*\DistanceInterFeuilles -0.5}) {Rachat};

% Noeud Vie
\node[noeudD] (Rbda) at (2,{\NiveauD - (1)*\DistanceInterFeuilles}) {Mortalité};
\node[noeudD] (Rbdb) at (2,{\NiveauD - (2)*\DistanceInterFeuilles}) {Longévité};
\node[noeudD] (Rbdc) at (2,{\NiveauD - (3)*\DistanceInterFeuilles}) {Incapacité Invalidité};
\node[noeudD] (Rbdd) at (2,{\NiveauD - (4)*\DistanceInterFeuilles}) {Rachat};
\node[noeudD] (Rbde) at (2,{\NiveauD - (5)*\DistanceInterFeuilles}) {Dépenses};
\node[noeudD] (Rbdf) at (2,{\NiveauD - (6)*\DistanceInterFeuilles}) {Révision};
\node[noeudD] (Rbdg) at (2,{\NiveauD - (7)*\DistanceInterFeuilles}) {Catas\-trophe};

% Noeud Non Vie
\node[noeudD] (Rbea) at (4.5,{\NiveauD - (1)*\DistanceInterFeuilles}) {Prime et réserve};
\node[noeudD] (Rbeb) at (4.5,{\NiveauD - (2)*\DistanceInterFeuilles}) {Rachat};
\node[noeudD] (Rbec) at (4.5,{\NiveauD - (3)*\DistanceInterFeuilles}) {Catas\-trophe};

\coordinate (interm1) at (0,-1);
\draw[segment] (R)-- (interm1) -| (Ra);
\draw[segment] (R)--(Rb);
\draw[segment] (R)-- (interm1) -| (Rc);

\coordinate (interm2) at (0,-3);
\draw[segment] (Rb) -- (interm2) -| (Rba);
\draw[segment] (Rb)-- (interm2) -| (Rbb);
\draw[segment] (Rb)-- (interm2) -| (Rbc);
\draw[segment] (Rb)-- (interm2) -| (Rbd);
\draw[segment] (Rb)-- (interm2) -| (Rbe);
\draw[segment] (Rb)-- (interm2) -| (Rbf);

\coordinate (interm3) at (-9.5,-5.5);
\draw[segment] (Rba)|-(interm3);
\draw[segment] (interm3)|-(Rbaa);
\draw[segment] (interm3)|-(Rbab);
\draw[segment] (interm3)|-(Rbac);
\draw[segment] (interm3)|-(Rbad);
\draw[segment] (interm3)|-(Rbae);
\draw[segment] (interm3)|-(Rbaf);
\draw[segment] (interm3)|-(Rbag);

\coordinate (interm4) at (-4.5,-5);
\draw[segment] (Rbb)-- (interm4) -| (Rbba);
\draw[segment] (Rbb)-- (interm4) -| (Rbbb);
\draw[segment] (Rbb)-- (interm4) -| (Rbbc);

\coordinate (interm5) at (-4,-7);
\draw[segment] (Rbba)|-(interm5);
\draw[segment] (interm5)|-(Rbbaa);
\draw[segment] (interm5)|-(Rbbab);
\draw[segment] (interm5)|-(Rbbac);
\draw[segment] (interm5)|-(Rbbad);
\draw[segment] (interm5)|-(Rbbae);
\draw[segment] (interm5)|-(Rbbaf);

\coordinate (interm6) at (-2.4,-7);
\draw[segment] (Rbbc)|-(interm6);
\draw[segment] (interm6)|-(Rbbca);
\draw[segment] (interm6)|-(Rbbcb);

\coordinate (interm7) at (0.5,-5.5);
\draw[segment] (Rbd)|-(interm7);
\draw[segment] (interm7)|-(Rbda);
\draw[segment] (interm7)|-(Rbdb);
\draw[segment] (interm7)|-(Rbdc);
\draw[segment] (interm7)|-(Rbdd);
\draw[segment] (interm7)|-(Rbde);
\draw[segment] (interm7)|-(Rbdf);
\draw[segment] (interm7)|-(Rbdg);

\coordinate (interm8) at (6,-5.5);
\draw[segment] (Rbe)|-(interm8);
\draw[segment] (interm8)|-(Rbea);
\draw[segment] (interm8)|-(Rbeb);
\draw[segment] (interm8)|-(Rbec);

\end{tikzpicture}

\end{document}

颜色是任意的,但正如您在示例中看到的,一些矩形在右上角有一个小三角形,我想重现这一点。对我来说,矩形显示为节点样式,但我不知道如何在其上添加额外内容。

答案1

一种可能性是添加path picture样式,例如

path picture={
   \fill [green!50!black] ([xshift=-4mm]path picture bounding box.north east) -| ([yshift=-4mm]path picture bounding box.north east) -- cycle;
  }

所以如果你有

noeudA/.style={
  rectangle,
  inner sep=0pt,
  text width=25mm,
  align=center,
  draw=black,
  fill=green!30,
  minimum height = 10mm,
  path picture={
   \fill [green!50!black] ([xshift=-4mm]path picture bounding box.north east) -| ([yshift=-4mm]path picture bounding box.north east) -- cycle;
  }
  }

然后你的图表的第一个节点将看起来像

在此处输入图片描述

或者,你可以创建一种upperlefttriangle以颜色为参数的新样式,即

upperlefttriangle/.style={
path picture={
   \fill [#1] ([xshift=-4mm]path picture bounding box.north east) -| ([yshift=-4mm]path picture bounding box.north east) -- cycle;
  }
}

然后使用

upperlefttriangle={<color>}

无论是其他风格,还是单独的节点。

答案2

在此处输入图片描述

MWE,更加简洁,因为 MWE 提供了(经过一些,实际上很多的努力:))结合treespositioning库:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{chains, positioning, trees}
\usepackage[utf8]{inputenc}
\newcommand\ppbb{path picture bounding box}

\begin{document}
\begin{tikzpicture}[
    node distance = 2mm and 2mm,
    start chain = going below,
base/.style = {rectangle, draw,
               fill=#1,
               inner sep=0mm,
               minimum height = 9mm, text width=25mm, align=center,
               font=\linespread{.9}\selectfont
               },
   T/.style = {path picture={\fill[cyan!75]
                (\ppbb.east) -- (\ppbb.north east) -- ++ (-4.5mm,0) -- cycle;
                             }% end of path picture
               },
boxB/.style = {base=#1, text width=20mm},
% on chain
 box/.style = {boxB=#1, on chain},
% tree's parameters
  level distance = 18mm,
sibling distance = 32mm,
  level 2/.style = {sibling distance = 25mm},
  level 3/.style = {sibling distance = 22mm}
                        ]
% first part of image
% start of tree
\node[base=teal!30] {SCR}
    [edge from parent fork down]
    child { node[base=teal!30]      {Ajustement}}
    child { node[base=teal!30,T]    {BSCR}
        child { node[boxB=teal!15,T]    (Rba)   {Marché}}
        child { node[boxB=teal!15,T]    (Rbb)   {Santé}
            child { node[boxB=teal!10,T](Rca)   {SLT}}
            child { node[boxB=teal!10,T](Rcb)   {Catastrophe}}
            child { node[boxB=teal!10]  (Rcc)   {NSLT}}
                }
        child { node[boxB=teal!15,T]    (Rbc)  {Contre-partie}}
        child { node[boxB=teal!15,T]    (Rbd)  {Vie}}
        child { node[boxB=teal!15]      (Rbe)  {Non-vie}}
        child { node[boxB=teal!15]      (Rbf)  {Actifs incorporels}}
            }
    child { node[base=teal!30]  {Opérationnel}};
% Noeud Marché
{[start chain]
\coordinate[on chain,below=of Rba.west |- Rca.south]   (a);
\node[box=blue!10,T] (Rbaa) {Taux d'intérêt};
\node[box=blue!10,T] (Rbab) {Action};
\node[box=blue!10,T] (Rbac) {Immobilier};
\node[box=blue!10,T] (Rbad) {Spread};
\node[box=blue!10,T] (Rbae) {Change};
\node[box=blue!10,T] (Rbaf) {Concen\-tration};
\node[box=blue!10,T] (Rbag) {Illiquidité};
}
% Noeud Santé
{[start chain]
\coordinate[on chain,below=of Rcb.south west]   (b);
\node[box=blue!10,T] (Rbbaa)  {Mortalité};
\node[box=blue!10,T] (Rbbab)  {Longévité};
\node[box=blue!10,T] (Rbbac)  {Incapacité Invalidité};
\node[box=blue!10,T] (Rbbad)  {Rachat};
\node[box=blue!10,T] (Rbbae)  {Dépenses };
\node[box=blue!10,T] (Rbbaf)  {Révision};
}
% Noeud NSLT
{[start chain]
\coordinate[on chain,below=of Rcc.south east -| Rbc.east]   (c);
\node[box=blue!10] (Rbbca)  {Prime et réserve};
\node[box=blue!10] (Rbbcb)  {Rachat};
}
% Noeud Vie
{[start chain]
\coordinate[on chain,below left=of Rcc.south -| Rbe.west]    (d);
\node[box=blue!10,T] (Rbda) {Mortalité};
\node[box=blue!10,T] (Rbdb) {Longévité};
\node[box=blue!10,T] (Rbdc) {Incapacité Invalidité};
\node[box=blue!10,T] (Rbdd) {Rachat};
\node[box=blue!10,T] (Rbde) {Dépenses};
\node[box=blue!10,T] (Rbdf) {Révision};
\node[box=blue!10,T] (Rbdg) {Catas\-trophe};
}
% Noeud Non Vie
{[start chain]
\coordinate[on chain,below left=of Rcc.south -| Rbf.west]    (e);
\node[box=blue!10,T] (Rbea)   {Prime et réserve};
\node[box=blue!10,T] (Rbeb)   {Rachat};
\node[box=blue!10,T] (Rbec)   {Catas\-trophe};
}
% lines a
\coordinate[left=of Rbaa.west] (aa);
\draw   (Rba) -- ++ (0,-0.9) -| (aa) -- (Rbaa);
\foreach \i [remember=\i as \ii (initially a)] in {b,c,...,g}
    \draw (aa |- Rba\ii) |- (Rba\i);
% lines b
\draw   (Rca) |- (Rbbaa);
\foreach \i [remember=\i as \ii (initially a)] in {b,c,...,f}
    \draw (Rca |- Rbba\ii) |- (Rbba\i);
% lines d
\draw   (Rcc) |- (Rbbca);
\draw   (Rcc) |- (Rbbcb);
% lines e
\draw   (Rbd) |- (Rbda);
\foreach \i [remember=\i as \ii (initially a)] in {b,c,...,g}
    \draw (Rbd |- Rbd\ii) |- (Rbd\i);
% lines f
\draw   (Rbe) |- (Rbea);
\foreach \i [remember=\i as \ii (initially a)] in {b,c}
    \draw (Rbe |- Rbe\ii) |- (Rbe\i);
\end{tikzpicture}
\end{document}

附录: 在这种情况下,当框图的第二部分中的所有节点都具有相同的颜色时,该部分的代码可以进一步减少:

% second part of image
    \begin{scope}[every node/.append style = {box=blue!10}] % define common style for all nodes in scope   
% Noeud Marché
{[start chain]
\coordinate[on chain,below=of Rba.west |- Rca.south]   (a);
\node[T] (Rbaa) {Taux d'intérêt};
\node[T] (Rbab) {Action};
\node[T] (Rbac) {Immobilier};
\node[T] (Rbad) {Spread};
\node[T] (Rbae) {Change};
\node[T] (Rbaf) {Concen\-tration};
\node[T] (Rbag) {Illiquidité};
}
% Noeud Santé
{[start chain]
\coordinate[on chain,below=of Rcb.south west]   (b);
\node[T] (Rbbaa)  {Mortalité};
\node[T] (Rbbab)  {Longévité};
\node[T] (Rbbac)  {Incapacité Invalidité};
\node[T] (Rbbad)  {Rachat};
\node[T] (Rbbae)  {Dépenses };
\node[T] (Rbbaf)  {Révision};
}
% Noeud NSLT
{[start chain]
\coordinate[on chain,below=of Rcc.south east -| Rbc.east]   (c);
\node  (Rbbca)  {Prime et réserve};
\node  (Rbbcb)  {Rachat};
}
% Noeud Vie
{[start chain]
\coordinate[on chain,below left=of Rcc.south -| Rbe.west]    (d);
\node[T] (Rbda) {Mortalité};
\node[T] (Rbdb) {Longévité};
\node[T] (Rbdc) {Incapacité Invalidité};
\node[T] (Rbdd) {Rachat};
\node[T] (Rbde) {Dépenses};
\node[T] (Rbdf) {Révision};
\node[T] (Rbdg) {Catas\-trophe};
}
% Noeud Non Vie
{[start chain]
\coordinate[on chain,below left=of Rcc.south -| Rbf.west]    (e);
\node[T] (Rbea)   {Prime et réserve};
\node[T] (Rbeb)   {Rachat};
\node[T] (Rbec)   {Catas\-trophe};
}
    \end{scope}

结果和以前一样。

相关内容