有人可以帮忙制作形状阴影并减少第一行和第二行之间的距离吗?
这就是我所寻找的阴影类型。
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\tikzstyle{block}=[rectangle,draw,fill=blue!20,text width=5em,text badly centered,rounded corners,minimum height=4em]
\begin{document}
\begin{tikzpicture}[node distance=3cm,auto]
\node[block] (n1) {First};
\node[block, right of=n1] (n2) {Second};
\node[block, right of=n2] (n3) {Third};
\node[block, below of=n2] (n4) {Forth};
\node[block, below of=n3] (n5) {Fifth};
\begin{scope}[>=stealth,line width=3pt]
\draw[->, cyan!50] (n1) -- (n2);
\draw[->,cyan!50] (n2) -- (n3);
\draw[->,cyan!50] (n2) -- (n4);
\draw[->,cyan!50] (n4) -- (n5);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
我定义了两种类型的阴影,drop shadow
和shadow
。你可以在第五个节点上看到区别。箭头没有阴影。如果你需要的话……我们拭目以待。
对于节点之间的距离,positioning
调用该库。
附录
一旦定义了节点,它们之间的箭头就可以用edge
或 命令引入to
。使用后者,也可以使用类似 的语法|-
。
为箭头添加阴影的简单解决方案也基于第二种形式的使用;每个箭头可以绘制两次。不过这不是最漂亮的解决方案。
代码
\documentclass[11pt, margin=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, shadows.blur, arrows.meta, shapes}
\tikzset{
drop shadow/.style={
blur shadow={%
shadow xshift=1.5pt,
shadow yshift=-1pt,
shadow blur steps=9,
shadow blur extra rounding=1.5pt%
},
},
shadow/.style={%
preaction={%
fill=black!20, transform canvas={xshift=2.5pt, yshift=-1.5pt}
}
},
block/.style={%
draw, rectangle, rounded corners,
orange!50!red!80!black, fill=orange!50!red!90!black,
text width=5em, text badly centered, text=white,
minimum height=4em
},
spear/.style={%
arrows={-Latex[length=1em, width=3ex]}, blue!50!cyan!70!black,
line width=1ex, shorten <=3pt, shorten >=3pt
}
}
\begin{document}
\begin{tikzpicture}[node distance=1cm and 2cm, auto]
\node[block, drop shadow] (n1) {First};
\node[block, drop shadow, right=of n1] (n2) {Second};
\node[block, drop shadow, right=of n2] (n3) {Third};
\node[block, drop shadow, below=of n2] (n4) {Forth};
\node[block, shadow, below=of n3] (n5) {Fifth};
\path[->] (n1) edge[spear] (n2)
(n2) edge[spear] (n3)
(n2) edge[spear] (n4)
(n3) edge[spear] (n5);
\end{tikzpicture}
\end{document}
对于附录,spearCS
创建了样式,
spearCS/.style={%
arrows={-Latex[length=1em, width=3ex]}, black!20,
line width=1ex, shorten <=5pt, shorten >=5pt,
transform canvas={xshift=2pt, yshift=-1.5pt}
进而
\draw[spearCS] (n1) to (n2);
\draw[spearCS] (n2) to (n3);
\draw[spearCS, rounded corners] (n2) |- (n5);
被使用。
答案2
您可以使用缩短> = 3pt:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\renewcommand{\baselinestretch}{4}
\tikzstyle{block}=[rectangle,draw,fill=blue!20,text width=5em,text badly centered,rounded corners,minimum height=4em]
\begin{document}
\begin{tikzpicture}[node distance=3cm,shorten >=3pt,shorten <=3pt]
\node[block] (n1) {First};
\node[block, right of=n1] (n2) {Second};
\node[block, right of=n2] (n3) {Third};
\node[block, below of=n2] (n4) {Forth};
\node[block, below of=n3] (n5) {Fifth};
\begin{scope}[>=stealth,line width=3pt]
\draw[->, cyan!50] (n1) -- (n2);
\draw[->,cyan!50] (n2) -- (n3);
\draw[->,cyan!50] (n2) -- (n4);
\draw[->,cyan!50] (n4) -- (n5);
\end{scope}
\end{tikzpicture}
\end{document}
答案3
我使用库arrows.meta
和positioning
。我无法同时设置线条粗细和箭头。我创建了一个绘制线条然后绘制箭头的命令。
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\tikzset{every node/.style={
draw=black,
fill=blue!20,
text width=5em,
text centered,
rounded corners,
minimum height=4em,
node distance=1cm and 2cm, auto
},
trait/.style={
line width=7pt,
cyan!50,
shorten >=7pt
},
arrow/.style={
-Triangle,
line width=3pt,
cyan!50
}
}
\newcommand{\joint}[2]{%
\draw[trait] (#1) -- (#2);
\draw[arrow] (#1) -- (#2);
}
\begin{document}
\begin{tikzpicture}
\node (n1) {First};
\node[right= of n1] (n2) {Second};
\node[right= of n2] (n3) {Third};
\node[below= of n2] (n4) {Forth};
\node[below= of n3] (n5) {Fifth};
\joint{n1}{n2}
\joint{n2}{n3}
\joint{n2}{n4}
\joint{n4}{n5}
\end{tikzpicture}
\end{document}
编辑2 有了Daniel N.的代码,我学会了同时做这两件事,代码就简化了
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\tikzset{every node/.style={
draw=black,
fill=blue!20,
text width=5em,
text centered,
rounded corners,
minimum height=4em,
node distance=1cm and 2cm, auto
},
trait/.style={
arrows={-Triangle[length=1em, width=3ex]},
line width=7pt,
cyan!50,
%shorten >=7pt
}
% arrow/.style={
% arrows={-Triangle[length=1em, width=3ex]},
% %-Triangle,
% line width=3pt,
% cyan!50
% }
}
% \newcommand{\joint}[2]{%
% \draw[trait] (#1) -- (#2);
% \draw[arrow] (#1) -- (#2);
% }
\begin{document}
\begin{tikzpicture}
\node (n1) {First};
\node[right= of n1] (n2) {Second};
\node[right= of n2] (n3) {Third};
\node[below= of n2] (n4) {Forth};
\node[below= of n3] (n5) {Fifth};
\draw[trait] (n1)--(n2);
\draw[trait] (n2)--(n3);
\draw[trait] (n2)--(n4);
\draw[trait] (n4)--(n5);
\end{tikzpicture}
\end{document}
答案4
通过使用arrows.meta
、positioning
和shadows
库以及简单的默认drop shadows
选项来定义节点的形状。对于节点定位,使用“定位”库语法(参见代码中的注释):
%\documentclass{article}
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
positioning,
shadows} % <---
\begin{document}
\begin{tikzpicture}[
node distance = 7mm and 11mm, % set desired distance between nodes <vertical> and <horizontal>
box/.style = {draw, fill=red, rounded corners,
minimum height=4em, text width=5em, align=flush center,
text=white,
drop shadow},
every edge/.append style = {draw=cyan, line width=3mm, -{Triangle[length=3mm,width=5mm]},
shorten <=1mm, shorten >=0.5mm}
]
%
\node[box] (n1) {First};
\node[box, right=of n1] (n2) {Second}; % observe "=of <node name>" instead yourd "of = <node name>"
\node[box, right=of n2] (n3) {Third};
\node[box, below=of n2] (n4) {Forth};
\node[box, below=of n3] (n5) {Fifth};
%
\draw (n1) edge (n2)
(n2) edge (n3)
(n2) edge (n4)
(n4) edge (n5);
\end{tikzpicture}
\end{document}
附录:
但是,如果您更喜欢模糊阴影,那么您需要shadows
加载blur.shadows
库(它也支持库)并在上面的代码中用以下shadow
选项替换节点选项:drop shadow
blur shadow
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
positioning,
shadows.blur} % <---
\begin{document}
\begin{tikzpicture}[
node distance = 7mm and 11mm, % set desired distance between nodes yvertical> and <horizontal>
box/.style = {draw, fill=red, rounded corners,
minimum height=4em, text width=5em, align=flush center,
text=white,
drop shadow},
every edge/.append style = {draw=cyan, line width=3mm, -{Triangle[length=3mm,width=5mm]},
shorten <=1mm, shorten >=0.5mm}
]
% rest is the same as in above MWE
编译结果:
注意:到目前为止,捆绑包文档blur.shadows
中尚未描述tikz
。有关详细信息,请参阅pgf-blur – PGF/TikZ 包。