我想要一个(大)节点长文 长文从单元格 m-2-2 的最左侧跨越到单元格 m-2-5 的最右侧。
我怎样才能实现这个目标?
平均能量损失
\documentclass[
11pt
]{scrartcl}
\usepackage{
tikz,
relsize,
tgheros
}
\usetikzlibrary{
calc,trees,shadows,positioning,arrows,chains,
decorations.pathreplacing,
decorations.pathmorphing,
decorations.shapes,
decorations.text,
shapes,
shapes.geometric,
shapes.symbols,
matrix,
patterns,
intersections,
fit
}
\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background layer,main,foreground layer}
\tikzset{
>=latex,
line/.style={draw, thick, ->},
phase/.style={
text height=1.5ex,
text depth=0.25ex,
align=left,
anchor=center,
% text width=6cm,
font=\sffamily\bfseries\small,
rectangle,
minimum height=1.0cm,
draw=black,
very thick,
fill=black!40
},
phasentext/.style={
align=left,
anchor=center,
%node distance=0.5cm,
rectangle,
minimum width=2cm,
minimum height=1cm,
% text width=7cm,
draw=gray,
very thick,
font=\sffamily\small
}
}
\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small,node distance=0.5cm]
\matrix (m) [
matrix of nodes,
nodes in empty cells,
row sep=6mm,
column sep=3mm,
inner sep=7pt
] {
%
|[phase]| 1 & & & & \\
& |[phasentext] (WordA)| Test: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
|[phasentext] (WordB)| Stuff:\tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
|[phasentext] (WordC)| Stuff text word: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
|[phasentext] (WordD)| Some more words: \begin{tikzpicture} \draw[thick] (0,0) circle [radius=6pt]; \draw[thick] (-3pt,-2pt) -- (3pt,-2pt) -- (0,2pt) -- cycle; \draw[thick] (0,2pt) -- (0,-2pt); \end{tikzpicture} \\
};
\node[phase, fit=(m-1-2)(m-1-5), align=left, text height=1.5ex, text depth=0.25ex] (Words) {Long text I suppose};
\end{tikzpicture}
\end{center}
\end{document}
关于标题:如果您能想到更好的标题,请随意编辑它。
答案1
这是matrix
添加长文本节点之前以及empty nodes
绘制的。如您所见,空节点是empty
,即没有任何内容,但有一些inner sep
。
您还可以看到为什么fit=(m-1-2)(m-1-5)
会产生比预期更短的节点。但它的大小是正确的,您的预期是错误的 ;-)
一个可能的解决方案是使用节点WordA
并WordD
固定长文本节点大小但将其对齐到第一行。
\node[phase, fit=(WordA)(WordD), align=left, text height=1.5ex, text depth=0.25ex,
anchor=west, inner sep=0pt] (Words)
at (m-1-1-|WordA.west) {\ Long text I suppose};
在上一行,我在\
节点文本前添加了(空格),因为我们需要修复inner sep=0pt
调整适合的节点大小。
完整代码如下
\documentclass[
11pt
]{scrartcl}
\usepackage{
tikz,
relsize,
tgheros
}
\usetikzlibrary{
calc,trees,shadows,positioning,arrows,chains,
decorations.pathreplacing,
decorations.pathmorphing,
decorations.shapes,
decorations.text,
shapes,
shapes.geometric,
shapes.symbols,
matrix,
patterns,
intersections,
fit
}
\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background layer,main,foreground layer}
\tikzset{
>=latex,
line/.style={draw, thick, ->},
phase/.style={
text height=1.5ex,
text depth=0.25ex,
align=left,
anchor=center,
% text width=6cm,
font=\sffamily\bfseries\small,
rectangle,
minimum height=1.0cm,
draw=black,
very thick,
fill=black!40
},
phasentext/.style={
align=left,
anchor=center,
%node distance=0.5cm,
rectangle,
minimum width=2cm,
minimum height=1cm,
% text width=7cm,
draw=gray,
very thick,
font=\sffamily\small
}
}
\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small,node distance=0.5cm]
\matrix (m) [
matrix of nodes,
nodes in empty cells,
row sep=6mm,
column sep=3mm,
inner sep=7pt,
] {
%
|[phase]| 1 & & & & \\
& |[phasentext] (WordA)| Test: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
|[phasentext] (WordB)| Stuff:\tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
|[phasentext] (WordC)| Stuff text word: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
|[phasentext] (WordD)| Some more words: \begin{tikzpicture} \draw[thick] (0,0) circle [radius=6pt]; \draw[thick] (-3pt,-2pt) -- (3pt,-2pt) -- (0,2pt) -- cycle; \draw[thick] (0,2pt) -- (0,-2pt); \end{tikzpicture} \\
};
\node[phase, fit=(WordA)(WordD), align=left, text height=1.5ex, text depth=0.25ex, anchor=west, inner sep=0pt] (Words) at (m-1-1-|WordA.west) {\ Long text I suppose};
\end{tikzpicture}
\end{center}
\end{document}
最终结果: