我遇到了一个愚蠢的问题。我似乎无法连接最后两个框。而且我想在其中一个框中放入 |.|,但我不知道该怎么做。有人能帮我解决这个问题吗?
\documentclass{standalone}
\usepackage{amsmath,amscd,amssymb,latexsym,upref} %stmaryrd
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usetikzlibrary{arrows.meta,
backgrounds,
chains,
fit,
quotes}
\begin{document}
\resizebox{16cm}{2cm}{%
\begin{tikzpicture}[auto,
node distance = 12mm,
start chain = A going right,
block/.style = {draw, fill=white,
text width=#1, minimum height=10mm, align=center,
outer sep=0pt, on chain},
block/.default = 18mm,
container/.style = {draw, fill=gray!50,
inner xsep=2mm, inner ysep=7mm},
]
\node [block=14mm] {a}; % block name is A-1
\node [block=12mm] {b};
\node [block=22mm] {c};
\node [block=15mm] {d};
\node [block=22mm] {e}; % block name is A-4
\node [block=22mm] {f}; % block name is A-6
\node [block=12mm] {g};
\node [block=24mm] {h}; % block name is A-8
\node [block=24mm] {i}; % block name is A-8
%
\scoped[on background layer]
\node [container, label={[anchor=north]joined},
fit= (A-5) (A-6)] (container) {};
\draw [-Stealth]
(A-1) edge (A-2) % text on arrow is between " and "
(A-2) edge (A-3)
(A-3) edge (A-4)
(A-4) edge (A-5)
(A-5) edge (A-6)
(A-6) edge (A-7);
(A-7) edge (A-8);
(A-8) edge (A-8);
\end{tikzpicture}
}
\end{document}
答案1
最后一个标记为 i 的块有名称A-9
,如果您输入分号,则需要添加新的绘制命令。我希望我正确理解了您的模数条请求。
\documentclass{standalone}
\usepackage{amsmath,amscd,amssymb,latexsym,upref} %stmaryrd
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usetikzlibrary{arrows.meta,
backgrounds,
chains,
fit,
quotes}
\begin{document}
\resizebox{16cm}{2cm}{%
\begin{tikzpicture}[auto,
node distance = 12mm,
start chain = A going right,
block/.style = {draw, fill=white,
text width=#1, minimum height=10mm, align=center,
outer sep=0pt, on chain},
block/.default = 18mm,
container/.style = {draw, fill=gray!50,
inner xsep=2mm, inner ysep=7mm},
]
\node [block=14mm] {a}; % block name is A-1
\node [block=12mm] {b};
\node [block=22mm] {c};
\node [block=15mm] {d};
\node [block=22mm] {e~$|.|$}; % block name is A-4
\node [block=22mm] {f}; % block name is A-6
\node [block=12mm] {g};
\node [block=24mm] {h}; % block name is A-8
\node [block=24mm] {i}; % block name is A-9
%
\scoped[on background layer]
\node [container, label={[anchor=north]joined},
fit= (A-5) (A-6)] (container) {};
\draw [-Stealth]
(A-1) edge (A-2) % text on arrow is between " and "
(A-2) edge (A-3)
(A-3) edge (A-4)
(A-4) edge (A-5)
(A-5) edge (A-6)
(A-6) edge (A-7)
(A-7) edge (A-8)
(A-8) edge (A-9);
\end{tikzpicture}
}
\end{document}
答案2
- 我对所讨论的 mwe 非常熟悉 :-)
- 您应该分析在 mwe 中使用的代码...然后您会观察到最后一个节点的名称是
A-9
(而不是A-8
您在 mwe 中指出的那样) - 对于最常见的尺寸,您应该选择它作为默认尺寸,例如
block/.default=22mm
,仅为其余部分写入所需的文本宽度(您真的需要如此不同的节点大小吗?我只会使用18mm
nad9mm
,请参阅下面的 mwe) - 您可以在节点中以文本形式写入数学表达式,例如 $|\cdot|$
*不要使用
\resizebox{16cm}{...
。它会调整图像中所有内容的大小并使其变得难看。而是重新计算节点的宽度和节点距离,使它们的总和为 16 厘米:14mm + 12mm + 22mm + 15mm + 22mm + 22mm +12mm +24mm +24mm + 9x2x(内间隔) +8*(节点距离)=
318 mm
这几乎是长度的两倍。我建议将所有图像元素的长度减半(参见下文)并使用较小的字体大小,例如
footnotesize
:
从 mwe 不遵循,您将在节点之间的箭头上添加文本。如果是这种情况,那么您可以使用库join
中的宏来绘制它们chains
考虑以上评论和建议,您的目标将变为:
\documentclass[margin=3mm]{standalone}
\usepackage{amsmath,amscd,amssymb,latexsym,upref} %stmaryrd
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{arrows.meta,
backgrounds,
chains,
fit,
quotes}
\begin{document}
\begin{tikzpicture}[
node distance = 7mm,
start chain = A going right,
block/.style = {draw, fill=white,
text width=#1, minimum height=10mm, align=center,
font=\footnotesize, inner sep=1mm, outer sep=0pt,
on chain, join=by -Stealth},
block/.default = 12mm,
container/.style = {draw, fill=gray!50,
inner xsep=2mm, inner ysep=7mm},
]
\node [block=6mm] {a}; % block name is A-1
\node [block=6mm] {b};
\node [block] {$|\cdot|$};
\node [block=6mm] {d};
\node [block] {e}; % block name is A-4
\node [block] {f}; % block name is A-6
\node [block=6mm] {g};
\node [block] {h};
\node [block] {i}; % block name is A-9
%
\scoped[on background layer]
\node [container, label={[anchor=north]joined},
fit= (A-5) (A-6)] (container) {};
\end{tikzpicture}
\end{document}
笔记:如果您喜欢标记节点之间的箭头,那么您应该join
从块样式定义中删除选项并向图像添加:
\draw [-Stealth]
(A-1) edge ["$\alpha$"] (A-2)
(A-2) edge ["$\beta$"] (A-3)
(A-3) edge ["$\gamma$"] (A-4)
(A-4) edge ["$\epsilon$"] (A-5)
(A-5) edge ["$\zeta$"] (A-6)
(A-6) edge ["$\theta$"] (A-7)
(A-7) edge ["$\iota$"] (A-8)
(A-8) edge ["$\kappa$"] (A-9);
并在图像选项中添加:
every edge quote/.append style = {font=\footnotesize}
绘制图像需要大量的耐心、准确性和时间......