如何将列元素放置在下方带有短标签的框内。
我尝试过,但没有得到想要的输出。当前编译的输出如下所示。
我想放置一个框来覆盖整个 D1 和 plk(D2) 节点,同样也覆盖其他两个节点,即 k1(D1) 和 D2(按列)。还想在该框下方放置一个标签。请帮助我。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, quotes, arrows.meta, arrows, calc, shadows, positioning}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[
node distance = 22mm and 22mm,
mybox/.style = {draw, ultra thick, text width=22mm, minimum height=11mm, align=center,
inner sep=2mm, outer sep=0mm},
every edge/.style = {draw, thick, shorten >=2mm, shorten <=2mm,
bend left, -Stealth},
every edge quotes/.append style={sloped, font=\sffamily\scriptsize, auto},
]
\begin{scope}
\node[] (sa) {D\textsubscript{1}};
\node[] (sb) [right=of sa] {kl(D\textsubscript{1})};
\node[] (sc) [below=of sa] {plk(D\textsubscript{2})};
\node[] (sd) [right=of sc] {D\textsubscript{2}};
\end{scope}
\draw
(sa) edge ["ald"] (sb)
(sb) edge ["ald\textsuperscript{-1}"] (sa)
(sc) edge ["sld"] (sd)
(sd) edge ["sld\textsuperscript{-1}"] (sc)
;
\end{tikzpicture}
\caption{Try.}
\label{f1}
\end{figure}
\end{document}
答案1
这接近吗?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, quotes, arrows.meta, arrows, calc, shadows, positioning}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[
node distance = 22mm and 22mm,
mybox/.style = {draw, ultra thick, text width=22mm, minimum height=11mm, align=center,
inner sep=2mm, outer sep=0mm},
every edge/.style = {draw, thick, shorten >=2mm, shorten <=2mm,
bend left, -Stealth},
every edge quotes/.append style={sloped, font=\sffamily\scriptsize, auto},
small box/.style={draw,minimum width=2em,minimum height=1em}
]
\begin{scope}
\node[] (sa) {D\textsubscript{1}};
\node[] (sb) [right=of sa] {kl(D\textsubscript{1})};
\node[] (sc) [below=of sa] {plk(D\textsubscript{2})};
\node[] (sd) [right=of sc] {D\textsubscript{2}};
\node[small box,label=below:x] at ($(sa)!0.5!(sb)$){};
\node[small box,label=below:y] at ($(sc)!0.5!(sd)$){};
\end{scope}
\draw
(sa) edge ["ald"] (sb)
(sb) edge ["ald\textsuperscript{-1}"'] (sa)
(sc) edge ["sld"] (sd)
(sd) edge ["sld\textsuperscript{-1}"'] (sc)
;
\end{tikzpicture}
\caption{Try.}
\label{f1}
\end{figure}
\end{document}
要将节点放入盒子中,请使用fit
库。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,bending,quotes, positioning,fit}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[
node distance = 25mm and 22mm,
mybox/.style = {draw, ultra thick, text width=22mm, minimum height=11mm, align=center,
inner sep=2mm, outer sep=0mm},
every edge/.style = {draw, thick, shorten >=2mm, shorten <=2mm,
bend left=60, -{Stealth[bend]}},
every edge quotes/.append style={sloped, font=\sffamily\scriptsize, auto},
]
\begin{scope}
\node[] (sa) {D\textsubscript{1}};
\node[] (sb) [right=of sa] {kl(D\textsubscript{1})};
\node[] (sc) [below=of sa] {plk(D\textsubscript{2})};
\node[] (sd) [right=of sc] {D\textsubscript{2}};
\node[fit=(sa)(sb),draw,inner ysep=0pt,label=below:x]{};
\node[fit=(sc)(sd),draw,inner ysep=0pt,label=below:y]{};
\end{scope}
\draw
(sa) edge ["ald"] (sb)
(sb) edge ["ald\textsuperscript{-1}"'] (sa)
(sc) edge ["sld"] (sd)
(sd) edge ["sld\textsuperscript{-1}"'] (sc)
;
\end{tikzpicture}
\caption{Try.}
\label{f1}
\end{figure}
\end{document}
答案2
这更新的问题说:
我想要放置一个覆盖整个 D1 和 plk(D2)节点的盒子,同样也覆盖另外两个节点,即 k1(D1)和 D2(按列)。
答案如下那个问题使用 Ti钾Zfit
库:
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{fit, shapes, quotes, arrows.meta, arrows, calc, shadows,
positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 40mm and 22mm,
mybox/.style = {draw, ultra thick, text width=22mm, minimum height=11mm,
align=center,
inner sep=2mm, outer sep=0mm},
every edge/.style = {draw, thick, shorten >=2mm, shorten <=2mm,
bend left, -Stealth},
every edge quotes/.append style={sloped, font=\sffamily\scriptsize, auto},
]
\begin{scope}
\node (sa) {D\textsubscript{1}};
\node (sb) [right=of sa] {kl(D\textsubscript{1})};
\node (sc) [below=of sa] {plk(D\textsubscript{2})};
\node (sd) [right=of sc] {D\textsubscript{2}};
\end{scope}
\draw
(sa.north -| sc.east) edge ["ald"] (sb.north west)
(sb.south west) edge ["ald\textsuperscript{-1}"] (sa.south -| sc.east)
(sc.north east) edge ["sld"] (sd.north -| sb.west)
(sd.south -| sb.west) edge ["sld\textsuperscript{-1}"] (sc.south east);
\path node (m) [draw, inner sep=0, outer sep=0, fit=(sa) (sc)] {}
node[font=\tiny, inner ysep = 0, below=1mm of m] {below A};
\path node (n) [draw, inner sep=0, outer sep=0, fit=(sb) (sd)] {}
node[font=\tiny, inner ysep = 0, below=1mm of n] {below B};
\end{tikzpicture}
\end{document}