如何设置与每种样式类型相关的标签样式?
例如:(来源如下)
- 我有一个“输入”样式(中圆圈)和一个“连接”样式(小点),我希望默认情况下标签位于下方,但它们默认位于上方。
- 我还有一个“块”样式(渐变阴影矩形),其不知何故已经有标签默认为下方,我想为标签使用较小的字体。
我不知道如何做这两件事,我唯一能想到的就是如何使用来every label/.style
改变所有标签的字体。
https://www.writelatex.com/read/jrwtbtqxntyz
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit}
\begin{document}
\begin{tikzpicture}[node distance=5mm,
block/.style={
% The shape:
rectangle, minimum size=6mm,
% The rest
thick,draw=black,
top color=white,
bottom color=black!10
},
input/.style={
% The shape:
circle, minimum size=1mm,
% The rest
thick,draw=black,
fill = white,
},
junction/.style={
% The shape:
circle, minimum size=0.5mm, inner sep=0pt,
% The rest
thick,draw=black,
fill = black
},
every label/.style={
font=\small
},
>=latex
]
\node (wcmd) [input, label=below:$\omega_{cmd}$]{};
\node (wcmd2) at (0,1) [input, label=$\omega_{cmd}$]{};
\node (jj) at (1,1) [junction, label=Z] {};
\node (C) [block, right=of wcmd] {C};
\node (D) [block,right=of C] {D};
\node (E) [block,right=of D, label=below:Hey] {E};
\node (F) [block,below=of D] {F};
\draw[->] (wcmd) -- (C);
\draw[->] (C) -- (D);
\end{tikzpicture}
\end{document}
答案1
如果希望不同样式下的标签具有不同的属性,一种方法是添加label
这些样式的定义。例如,如果我希望样式中的标签block
为红色,字体较小,默认位置在东北,我会将block
样式定义为
block/.style={
<list of other keys>,
label={[red,font=\small]above left: #1},
}
并使用\node[block={<label text>}]{<node text>};
,其中block
采用一个参数(可以为空)来指定标签文本。
完整代码
\documentclass\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit}
\begin{document}
\begin{tikzpicture}[node distance=5mm,
block/.style={
% The shape:
rectangle, minimum size=6mm,
% The rest
thick,draw=black,
top color=white,
bottom color=black!10,
label={[red,font=\small]above right:#1}, % label for 'block'
},
input/.style={
% The shape:
circle, minimum size=1mm,
% The rest
thick,draw=black,
fill = white,
label={[orange,font=\tiny]below:#1} % label for 'input'
},
junction/.style={
% The shape:
circle, minimum size=0.5mm, inner sep=0pt,
% The rest
thick,draw=black,
fill = black,
label={[blue,font=\footnotesize]below:#1} % label for 'junction'
},
>=latex
]
\node (wcmd) [input=$\omega_{cmd}$]{};
\node (wcmd2) at (0,1) [input=$\omega_{cmd}$]{};
\node (jj) at (1,1) [junction=Z] {};
\node (C) [block, right=of wcmd] {C};
\node (D) [block,right=of C] {D};
\node (E) [block={Hey},right=of D] {E};
\node (F) [block,below=of D] {F};
\draw[->] (wcmd) -- (C);
\draw[->] (C) -- (D);
\end{tikzpicture}
\end{document}