我按照以下方式创建了一个流程图
\tikzstyle{steps} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=gray!50]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=2cm, text centered, text width=4cm, draw=black, fill=white]
\definecolor{arrowblue}{RGB}{98,145,224}
\newcommand\ImageNode[3][]{
\node[draw=arrowblue!80!black,linewidth=1pt,#1](#2){\includegraphics[width=1.5cm,height=1.5cm]{#3}};
}
\begin{tikzpicture}[node distance=2cm]
\node (step1) [steps] {Step 1};
\node (step2) [steps, right of=step1, xshift=3cm]{Step 2};
\node (step3) [steps, right of=step2, xshift=3cm]{Step 3};
\node (process1) [process, below of=step1] {text text};
\node (process2) [process, right of=process1, xshift=3cm] {text text
text text text text text text text text text text text text text text text text};
\node (process3) [process, right of=process2, xshift=3cm] {text text text};
\end{tikzpicture}
我想为步骤 1、步骤 2 和步骤 3 添加红色渐变的背景颜色。我不确定如何执行此操作,因为当前设置中未将步骤 1、步骤 2 和步骤 3 指定为列。
关于如何做到这一点的任何建议都将非常有用。
编辑:我正在寻找一种方法来创建列并填充给定列中节点的背景颜色。我不想给节点上色。我希望步骤 1 中的框位于列 1、步骤 2-列 2 和步骤 3-列 3 中
编辑 2:我发现流程图周围有额外的方框,我不确定为什么会出现这种情况。任何关于如何删除这些线条的建议都将非常有帮助。
编辑 3:我已将 decision/.style = {diamond, minimum height=1cm, draw=black, fill=white, inner sep=2mm} 添加到下面提供的解决方案中
列高不均匀。我找不到设置maximum height
样式的选项。关于如何设置统一列高的建议将非常有用。
答案1
像这样?
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds,
fit,
positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 4mm and 4mm,
base/.style = {rectangle, draw, align=center},
steps/.style = {base, rounded corners, fill=gray!50,
minimum height=1cm, text width=3cm},
process/.style = {base,
minimum height=2cm, text width=4cm, fill=white}
]
\node (process1) [process] {text text};
\node (process2) [process, right=of process1] {text text
text text text text text text text text text text text text text text text text};
\node (process3) [process, right=of process2] {text text text};
\node (step1) [steps, above=of process1] {Step 1};
\node (step2) [steps, above=of process2] {Step 2};
\node (step3) [steps, above=of process3] {Step 3};
%
\scoped[on background layer]
{
\node[fit=(step1) (process1), fill=red!20] {};
\node[fit=(step2) (process2), fill=red!40] {};
\node[fit=(step3) (process3), fill=red!60] {};
}
\end{tikzpicture}
\end{document}
附录:如果您使用article
字体大小为 12 pt 的文档类,则需要在上述建议的解决方案中进行以下更改:替换\documentclass[tikz, margin=3mm]{standalone}
为
\documentclass[12pt]{article}
\usepackage{tikz}
并减少节点的宽度(否则会突出右文本边框)。
在此更改时,您可以稍微改进图像代码,如以下 MWE 中所做的那样:
\documentclass[12pt]{article} % changed
\usepackage{tikz} % added
\usetikzlibrary{backgrounds,
fit,
positioning}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[
node distance = 4mm and 5mm,
base/.style = {rectangle, draw, inner sep=2mm, align=center},
steps/.style = {base, rounded corners, fill=gray!50,
minimum height=1cm, text width=24mm}, % changed
process/.style = {base,
minimum height=3cm, text width=34mm, % changed
fill=white},
FIT/.style args = {#1/#2}{base, draw=none, fit=#1, fill=#2} % added
]
\node (process1) [process] {text text};
\node (process2) [process, right=of process1] {text text
text text text text text text text text text text text text text text text text};
\node (process3) [process, right=of process2] {text text text};
\node (step1) [steps, above=of process1] {Step 1};
\node (step2) [steps, above=of process2] {Step 2};
\node (step3) [steps, above=of process3] {Step 3};
%
\scoped[on background layer]
{
\node[FIT=(step1) (process1)/red!20] {};
\node[FIT=(step2) (process2)/red!40] {};
\node[FIT=(step3) (process3)/red!60] {};
}
\end{tikzpicture}
\end{figure}
\end{document}
现在的结果(在我看来)更好一些:-):
答案2
背景颜色由选项决定fill=
。将其从流程样式中取出,并分别放入每个节点中。
平均能量损失
\documentclass{article}
\usepackage{tikz}
\tikzstyle{steps} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=gray!50]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=2cm, text centered, text width=4cm, draw=black]
\definecolor{arrowblue}{RGB}{98,145,224}
\newcommand\ImageNode[3][]{
\node[draw=arrowblue!80!black,linewidth=1pt,#1](#2){\includegraphics[width=1.5cm,height=1.5cm]{#3}};
}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (step1) [steps] {Step 1};
\node (step2) [steps, right of=step1, xshift=3cm]{Step 2};
\node (step3) [steps, right of=step2, xshift=3cm]{Step 3};
\node (process1) [fill=red!10, process, below of=step1] {text text};
\node (process2) [fill=red!30, process, right of=process1, xshift=3cm] {text text
text text text text text text text text text text text text text text text text};
\node (process3) [fill=red!90, process, right of=process2, xshift=3cm] {text text text};
\end{tikzpicture}
\end{document}