如何在 tikz 中叠加图形、合并形状并添加文本?

如何在 tikz 中叠加图形、合并形状并添加文本?

我想改变这个图表https://texample.net/tikz/examples/arrow-table/这样,“入站”和“物流”就覆盖了所有 4 条上行线 - 同时还可以在上面面板上创建四个字段进行写入。对于运营,我希望它只覆盖当前包含“技术和开发”以及“采购”的行。

我还想将“营销和销售”和“服务领域”结合起来,并将其与上面的两行叠加。

为了实现我的目标,我有几个问题:

  1. 如何在 tikz 中叠加字段?我找到了这个页面,https://tikz.dev/tikz-transparency

  2. 我怎样才能使上部的文本位于新创建的较小区域中?

  3. 我怎样才能合并错误下部的字段。

我知道这不是一个简单的例子,然而,我真的希望能对我的 3 个问题有所帮助。

为了方便起见,下面是来自 texasmple 的代码

% Table in the shape of an arrow
% Author: Gonzalo Medina
\usepackage{tikz}
\usetikzlibrary{calc,matrix,decorations.markings,decorations.pathreplacing}

\definecolor{colone}{RGB}{209,220,204}
\definecolor{coltwo}{RGB}{204,222,210}
\definecolor{colthree}{RGB}{207,233,232}
\definecolor{colfour}{RGB}{248,243,214}
\definecolor{colfive}{RGB}{245,238,197}
\definecolor{colsix}{RGB}{243,235,179}
\definecolor{colseven}{RGB}{241,231,163}

\tikzset{ 
  table/.style={
    matrix of nodes,
    row sep=-\pgflinewidth,
    column sep=-\pgflinewidth,
    nodes={rectangle,text width=2cm,align=center},
    text depth=1.25ex,
    text height=2.5ex,
    nodes in empty cells
  }
}

\renewcommand*{\familydefault}{\sfdefault}
\newcommand{\cbox}[1]{\parbox[t]{2cm}{\centering #1}}

\begin{document}

\begin{tikzpicture}
  \matrix (mat) [table] {
    |[fill=colfour]|      & |[fill=colfour]|  & |[fill=colfour]|
      & |[fill=colfour]|  & |[fill=colfour]|  &                   \\
    |[fill=colfive]|      & |[fill=colfive]|  & |[fill=colfive]|
      & |[fill=colfive]|  & |[fill=colfive]|  &                   \\
    |[fill=colsix]|       & |[fill=colsix]|   & |[fill=colsix]|
      & |[fill=colsix]|   & |[fill=colsix]|   & |[fill=colsix]|   \\
    |[fill=colseven]|     & |[fill=colseven]| & |[fill=colseven]|
      & |[fill=colseven]| & |[fill=colseven]| & |[fill=colseven]| \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   & |[fill=colone]|   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   & |[fill=colone]|   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   &                   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   &                   \\
  };

  % horizontal rules
  \foreach \row in {2,3,4}
    \draw[white] (mat-\row-1.north west) -- (mat-\row-6.north east);
  \draw[white,ultra thick] (mat-1-1.north west) -- (mat-1-6.north east);
  \draw[white,ultra thick] (mat-5-1.north west) -- (mat-5-6.north east);

  % vertical rules
  \foreach \col in {2,3,4,5}
    \draw[white] (mat-5-\col.north west) -- (mat-8-\col.south west);

  % The labels
  \node[fill=colfour] at (mat-1-3) {Firm Infrastructure};
  \node[fill=colfive] at (mat-2-3) {Human Resources Management};
  \node[fill=colsix] at (mat-3-3) {Technology Development};
  \node[fill=colseven] at (mat-4-3) {Procurement};
  \node at ([yshift=-10pt]mat-6-1) {\cbox{Inbound Logistics}};
  \node at ([yshift=-10pt]mat-6-2) {\cbox{Operations \\\mbox{}}};
  \node at ([yshift=-10pt]mat-6-3) {\cbox{Outbound Logistics}};
  \node at ([yshift=-10pt]mat-6-4) {\cbox{Marketing \& Sales}};
  \node at ([yshift=-10pt]mat-6-5) {\cbox{Service \\\mbox{}}};
  \node[rotate = 90] at ([xshift=-52pt]mat-3-1.north)
    {\textsc{Support Activities}};
  \node at ([yshift=-19pt, xshift=-0.5cm]mat-8-3.south)
    {\textsc{Primary Activities}};

  % Erase some visible lines outside the arrow
  \fill[white] (mat-1-5.north east) -- (mat-5-6.north east)
    -- (mat-1-6.north east) -- cycle;
  \fill[white] (mat-8-5.north east) -- (mat-5-6.north east)
    -- (mat-8-6.north east) -- cycle;

  % Draw the arrow tip
  \shade[top color=colfour!70, bottom color=colfour!70,
    middle color=colseven, draw=white, ultra thick] 
    (mat-1-5.north) -- (mat-5-6.north) -- (mat-8-5.south) -- 
    (mat-8-5.south east) -- (mat-5-6.north east) -- (mat-8-5.south east) -- 
    (mat-5-6.north east) -- (mat-1-5.north east) -- cycle;

  % The slanted "Margin" labels
  \begin{scope}[decoration={markings,
    mark=at position .5 with \node[transform shape] {Margin};}]
  \path[postaction={decorate}] 
    ( $ (mat-1-5.north)!0.5!(mat-1-5.north east) $ )
    -- ( $ (mat-5-6.north)!0.5!(mat-5-6.north east) $ );
  \path[postaction={decorate}] 
    ( $ (mat-5-6.north)!0.5!(mat-5-6.north east) $ )
    -- ( $ (mat-8-5.south)!0.5!(mat-8-5.south east) $ );
  \end{scope}

  % The braces
  \draw[decorate, decoration={brace, mirror, raise=6pt}]
    (mat-1-1.north west) -- (mat-5-1.north west);
  \draw[decorate, decoration={brace, mirror, raise=6pt}]
    (mat-8-1.south west) -- (mat-8-5.south);
\end{tikzpicture}
\end{document}```

答案1

您应该花一点时间来了解图表是如何构建的,这样实现您想要的就不会太复杂。

首先,整个事情基于一个矩阵。这个矩阵由六列和八行组成。

剥去彩色框和节点后,它看起来像下面的图片(但我保留了尖端和括号):

在此处输入图片描述

现在,这个矩阵的单个单元格只是用特定的颜色填充,并且在某些单元格的边框上添加了白线。这样,看起来好像不同的单元格是相连的,但实际上并非如此。有些单元格之间根本没有边框。

最后,包含文本的节点的定位方式是,文本大致位于上述方法生成的彩色形状的中心。因此,文本标签与它们所在的形状完全无关。

总而言之,您无需合并形状或叠加“字段”即可实现所需效果。您只需更改某些单元格的颜色、重新绘制某些线条,并重新定位某些包含文本的节点即可。如果您愿意,还可以添加更多节点以添加更多文本。

我不太确定这是否与您想要实现的目标相似,但我猜至少它可以作为一个起点:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,decorations.markings,decorations.pathreplacing}

\definecolor{colone}{RGB}{209,220,204}
\definecolor{coltwo}{RGB}{204,222,210}
\definecolor{colthree}{RGB}{207,233,232}
\definecolor{colfour}{RGB}{248,243,214}
\definecolor{colfive}{RGB}{245,238,197}
\definecolor{colsix}{RGB}{243,235,179}
\definecolor{colseven}{RGB}{241,231,163}

\tikzset{ 
  table/.style={
    matrix of nodes,
    row sep=-\pgflinewidth,
    column sep=-\pgflinewidth,
    nodes={rectangle,text width=2cm,align=center},
    text depth=1.25ex,
    text height=2.5ex,
    nodes in empty cells
  }
}

\renewcommand*{\familydefault}{\sfdefault}
\newcommand{\cbox}[1]{\parbox[t]{2cm}{\centering #1}}

\begin{document}

\begin{tikzpicture}
  \matrix (mat) [table] {
    |[fill=colone]|      & |[fill=colfour]|  & |[fill=colfour]|
      & |[fill=colfour]|  & |[fill=colfour]|  &                   \\
    |[fill=colone]|      & |[fill=colfive]|  & |[fill=colfive]|
      & |[fill=colfive]|  & |[fill=colfive]|  &                   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colsix]|
      & |[fill=colsix]|   & |[fill=colsix]|   & |[fill=colsix]|   \\
    |[fill=colone]|     & |[fill=coltwo]| & |[fill=colseven]|
      & |[fill=colseven]| & |[fill=colseven]| & |[fill=colseven]| \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   & |[fill=colone]|   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   & |[fill=colone]|   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   &                   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   &                   \\
  };

  % horizontal rules
  \foreach \row in {2,3}
    \draw[white] (mat-\row-2.north west) -- (mat-\row-6.north east);
  
  \draw[white] (mat-4-3.north west) -- (mat-4-6.north east);
  \draw[white,ultra thick] (mat-3-2.north west) -- (mat-3-2.north east);
  \draw[white,ultra thick] (mat-5-3.north west) -- (mat-5-6.north east);

  % vertical rules
  \foreach \col in {4,5}
    \draw[white] (mat-5-\col.north west) -- (mat-8-\col.south west);

  \draw[white] (mat-1-2.north west) -- (mat-8-2.south west);
  \draw[white] (mat-3-3.north west) -- (mat-8-3.south west);

  % The labels
  \node at (mat-1-3) {Firm Infrastructure};
  \node at (mat-2-3) {Human Resources Management};
  \node at (mat-3-4) {Technology Development};
  \node at (mat-4-4) {Procurement};
  \node at ([yshift=-10pt]mat-6-1) {\cbox{Inbound Logistics}};
  \node at ([yshift=-10pt]mat-6-2) {\cbox{Operations \\\mbox{}}};
  \node at ([yshift=-10pt]mat-6-3) {\cbox{Outbound Logistics}};
  \node at ([yshift=-10pt]mat-6-4) {\cbox{Marketing \& Sales}};
  \node at ([yshift=-10pt]mat-6-5) {\cbox{Service \\\mbox{}}};
  \node[rotate = 90] at ([xshift=-52pt]mat-3-1.north)
    {\textsc{Support Activities}};
  \node at ([yshift=-19pt, xshift=-0.5cm]mat-8-3.south)
    {\textsc{Primary Activities}};

  % Erase some visible lines outside the arrow
  \fill[white] (mat-1-5.north east) -- (mat-5-6.north east)
    -- (mat-1-6.north east) -- cycle;
  \fill[white] (mat-8-5.north east) -- (mat-5-6.north east)
    -- (mat-8-6.north east) -- cycle;

  % Draw the arrow tip
  \shade[top color=colfour!70, bottom color=colfour!70,
    middle color=colseven, draw=white, ultra thick] 
    (mat-1-5.north) -- (mat-5-6.north) -- (mat-8-5.south) -- 
    (mat-8-5.south east) -- (mat-5-6.north east) -- (mat-8-5.south east) -- 
    (mat-5-6.north east) -- (mat-1-5.north east) -- cycle;

  % The slanted "Margin" labels
  \begin{scope}[decoration={markings,
    mark=at position .5 with \node[transform shape] {Margin};}]
  \path[postaction={decorate}] 
    ( $ (mat-1-5.north)!0.5!(mat-1-5.north east) $ )
    -- ( $ (mat-5-6.north)!0.5!(mat-5-6.north east) $ );
  \path[postaction={decorate}] 
    ( $ (mat-5-6.north)!0.5!(mat-5-6.north east) $ )
    -- ( $ (mat-8-5.south)!0.5!(mat-8-5.south east) $ );
  \end{scope}

  % The braces
  \draw[decorate, decoration={brace, mirror, raise=6pt}]
    (mat-1-1.north west) -- (mat-5-1.north west);
  \draw[decorate, decoration={brace, mirror, raise=6pt}]
    (mat-8-1.south west) -- (mat-8-5.south);
\end{tikzpicture}
\end{document}

在此处输入图片描述


或者也许你正在追求这样的事情:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,decorations.markings,decorations.pathreplacing}

\definecolor{colone}{RGB}{209,220,204}
\definecolor{coltwo}{RGB}{204,222,210}
\definecolor{colthree}{RGB}{207,233,232}
\definecolor{colfour}{RGB}{248,243,214}
\definecolor{colfive}{RGB}{245,238,197}
\definecolor{colsix}{RGB}{243,235,179}
\definecolor{colseven}{RGB}{241,231,163}

\tikzset{ 
  table/.style={
    matrix of nodes,
    row sep=-\pgflinewidth,
    column sep=-\pgflinewidth,
    nodes={rectangle,text width=2cm,align=center},
    text depth=1.25ex,
    text height=2.5ex,
    nodes in empty cells
  }
}

\renewcommand*{\familydefault}{\sfdefault}
\newcommand{\cbox}[1]{\parbox[t]{2cm}{\centering #1}}

\begin{document}

\begin{tikzpicture}
  \matrix (mat) [table] {
    |[fill=colone]|      & |[fill=colfour]|  & |[fill=colfour]|
      & |[fill=colfour]|  & |[fill=colfour]|  &                   \\
    |[fill=colone]|      & |[fill=colfive]|  & |[fill=colfive]|
      & |[fill=colfive]|  & |[fill=colfive]|  &                   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colsix]|
      & |[fill=colsix]|   & |[fill=colsix]|   & |[fill=colsix]|   \\
    |[fill=colone]|     & |[fill=coltwo]| & |[fill=colseven]|
      & |[fill=colseven]| & |[fill=colseven]| & |[fill=colseven]| \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   & |[fill=colone]|   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   & |[fill=colone]|   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   &                   \\
    |[fill=colone]|       & |[fill=coltwo]|   & |[fill=colthree]|
      & |[fill=coltwo]|   & |[fill=colone]|   &                   \\
  };

  % horizontal rules
  \foreach \row in {2,3,4}
    \draw[white] (mat-\row-1.north west) -- (mat-\row-6.north east);

  \draw[white,ultra thick] (mat-5-1.north west) -- (mat-5-6.north east);

  % vertical rules
  \foreach \col in {4,5}
    \draw[white] (mat-5-\col.north west) -- (mat-8-\col.south west);

  \draw[white] (mat-1-2.north west) -- (mat-8-2.south west);
  \draw[white] (mat-3-3.north west) -- (mat-8-3.south west);

  % The labels
  \node at (mat-1-3) {Firm Infrastructure};
  \node at (mat-2-3) {Human Resources Management};
  \node at (mat-3-4) {Technology Development};
  \node at (mat-4-4) {Procurement};

  \node at (mat-1-1) {One};
  \node at (mat-2-1) {Two};
  \node at (mat-3-1) {Three};
  \node at (mat-4-1) {Four};
  
  \node at (mat-3-2) {Five};
  \node at (mat-4-2) {Six};

  \node at ([yshift=-10pt]mat-6-1) {\cbox{Inbound Logistics}};
  \node at ([yshift=-10pt]mat-6-2) {\cbox{Operations \\\mbox{}}};
  \node at ([yshift=-10pt]mat-6-3) {\cbox{Outbound Logistics}};
  \node at ([yshift=-10pt]mat-6-4) {\cbox{Marketing \& Sales}};
  \node at ([yshift=-10pt]mat-6-5) {\cbox{Service \\\mbox{}}};
  \node[rotate = 90] at ([xshift=-52pt]mat-3-1.north)
    {\textsc{Support Activities}};
  \node at ([yshift=-19pt, xshift=-0.5cm]mat-8-3.south)
    {\textsc{Primary Activities}};

  % Erase some visible lines outside the arrow
  \fill[white] (mat-1-5.north east) -- (mat-5-6.north east)
    -- (mat-1-6.north east) -- cycle;
  \fill[white] (mat-8-5.north east) -- (mat-5-6.north east)
    -- (mat-8-6.north east) -- cycle;

  % Draw the arrow tip
  \shade[top color=colfour!70, bottom color=colfour!70,
    middle color=colseven, draw=white, ultra thick] 
    (mat-1-5.north) -- (mat-5-6.north) -- (mat-8-5.south) -- 
    (mat-8-5.south east) -- (mat-5-6.north east) -- (mat-8-5.south east) -- 
    (mat-5-6.north east) -- (mat-1-5.north east) -- cycle;

  % The slanted "Margin" labels
  \begin{scope}[decoration={markings,
    mark=at position .5 with \node[transform shape] {Margin};}]
  \path[postaction={decorate}] 
    ( $ (mat-1-5.north)!0.5!(mat-1-5.north east) $ )
    -- ( $ (mat-5-6.north)!0.5!(mat-5-6.north east) $ );
  \path[postaction={decorate}] 
    ( $ (mat-5-6.north)!0.5!(mat-5-6.north east) $ )
    -- ( $ (mat-8-5.south)!0.5!(mat-8-5.south east) $ );
  \end{scope}

  % The braces
  \draw[decorate, decoration={brace, mirror, raise=6pt}]
    (mat-1-1.north west) -- (mat-5-1.north west);
  \draw[decorate, decoration={brace, mirror, raise=6pt}]
    (mat-8-1.south west) -- (mat-8-5.south);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容