
Tenho uma rede feita em Tikz. O gráfico possui três camadas de nós. Preciso desenhar uma linha pontilhada conectando os nós e colocar um rótulo de camada próximo ao nó mais à direita ($m_1$, $j$ e $i$) - Camadas 1, 2 e 3.
\documentclass[]{report}
\usepackage{tikz}
\usetikzlibrary{arrows, automata, arrows.meta, positioning, calc}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[
> = stealth, % arrow head style
shorten > = 1pt, % don't touch arrow head to node
auto,
node distance = 3cm, % distance between nodes
semithick % line style
]
\tikzstyle{every state}=[
draw = black,
thick,
fill = white,
minimum size = 4mm
]
\node [dashed, state] (a) {$i$};
\node[state] (b) at ($ (a) + (45:1.5) $) {$j$};
\node[dashed, state] (c) at ($ (a) + (135:1.5) $) {$k$};
\node[state] (d) at ($ (c) + (45:2.1) $) {$m_1$};
\node[dashed, state] (e) at ($ (c) + (90:1.5) $) {$m_2$};
\node[state] (d1) at ($ (c) + (135:2.1) $) {$m_3$};
\path[->] (d) edge node {} (c);
\path[->] (d1) edge node {} (c);
\path[dashed,->] (e) edge node {} (c);
\path[->] (b) edge node {} (a);
\path[dashed, ->] (c) edge node {} (a);
\end{tikzpicture}
\label{fig:assembly-eg}
\end{figure}
\end{document}
Responder1
Bem-vindo! Algo assim? Você pode usar a local bounding box
para alinhar os rótulos das camadas. Observe também que \tikzstyle
está obsoleto.
\documentclass[]{report}
\usepackage{tikz}
\usetikzlibrary{automata, arrows.meta, positioning, calc}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[
> = stealth, % arrow head style
shorten > = 1pt, % don't touch arrow head to node
auto,
node distance = 3cm, % distance between nodes
semithick % line style
]
\begin{scope}[local bounding box=tree,every state/.style={draw = black,thick,
fill = white,minimum size = 4mm}]
\node [dashed, state] (a) {$i$};
\node[state] (b) at ($ (a) + (45:1.5) $) {$j$};
\node[dashed, state] (c) at ($ (a) + (135:1.5) $) {$k$};
\node[state] (d) at ($ (c) + (45:2.1) $) {$m_1$};
\node[dashed, state] (e) at ($ (c) + (90:1.5) $) {$m_2$};
\node[state] (d1) at ($ (c) + (135:2.1) $) {$m_3$};
\path ([xshift=1em]tree.east); %<-increase local bounding box
\end{scope}
\draw[dotted] (d1) -- (e) -- (d) -- (d-|tree.east) node[right]{1};
\draw[dotted] (c) -- (b) -- (b-|tree.east) node[right]{2};
\draw[dotted] (a) -- (a-|tree.east) node[right]{3};
\path[->] (d) edge node {} (c);
\path[->] (d1) edge node {} (c);
\path[dashed,->] (e) edge node {} (c);
\path[->] (b) edge node {} (a);
\path[dashed, ->] (c) edge node {} (a);
\end{tikzpicture}
\label{fig:assembly-eg}
\end{figure}
\end{document}