适合的标签可以相对于它放置,例如:
\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,fit,backgrounds}
\tikzstyle{back}=[rectangle,
fill=blue!30,
inner sep=0.2cm,
rounded corners=3mm]
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=1cm,on grid,auto]
\node[] (1) {\textbf{1}};
\node[] (2) [right= of 1] {\textbf{2}};
\begin{pgfonlayer}{background}
\node [back,
fit=(1) (2),
label=above:{\tiny Introduction}] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
但是,如果我想将该标签向右移动,该怎么办?\xshift
在这种情况下我该如何使用?
答案1
这对我有用。
也可以看看应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?。
\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,fit,backgrounds}
\tikzset{
back/.style={rectangle,
fill=blue!30,
inner sep=0.2cm,
rounded corners=3mm},
}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=1cm,on grid,auto]
\node (1) {\textbf{1}};
\node (2) [right= of 1] {\textbf{2}};
\begin{pgfonlayer}{background}
\node [back,
fit=(1) (2),
label={[xshift=2mm]above:{\tiny Introduction}}] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}