我正在使用elsarticle
课程,我需要一些帮助来缩放我的 tikzpicture。
\documentclass[numbers,preprint,review,12pt,sort&compress]{elsarticle}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.5]
% Node styles
\tikzstyle{circulo_vermelho}=[fill=red, draw=black, shape=circle]
\tikzstyle{circulo_cinza}=[fill={rgb,255: red,128; green,128; blue,128}, draw=black, shape=circle]
\tikzstyle{circulo_verde}=[fill=green, draw=black, shape=circle]
\tikzstyle{circulo_amarelo}=[fill=yellow, draw=black, shape=circle]
\tikzstyle{circulo_azul}=[fill=blue, draw=black, shape=circle]
\tikzstyle{texto}=[fill=none, draw=none, shape=circle]
% Edge styles
\tikzstyle{seta}=[->]
\node [style={circulo_cinza}] (0) at (0, 5) {};
\node [style={circulo_cinza}] (1) at (0, 3.5) {};
\node [style={circulo_cinza}] (2) at (0, 2) {};
\node [style={circulo_vermelho}] (3) at (3.5, 5) {};
\node [style={circulo_vermelho}] (4) at (3.5, 3.5) {};
\node [style={circulo_vermelho}] (5) at (3.5, 2) {};
\node [style={circulo_vermelho}] (6) at (7, 5) {};
\node [style={circulo_vermelho}] (7) at (7, 3.5) {};
\node [style={circulo_vermelho}] (8) at (7, 2) {};
\node [style={circulo_cinza}] (9) at (0, -3) {};
\node [style={circulo_cinza}] (10) at (0, -4.5) {};
\node [style={circulo_cinza}] (11) at (0, -6) {};
\node [style={circulo_azul}] (12) at (7, -3) {};
\node [style={circulo_azul}] (13) at (7, -4.5) {};
\node [style={circulo_azul}] (14) at (7, -6) {};
\node [style={circulo_verde}] (15) at (11.5, 1) {};
\node [style={circulo_verde}] (16) at (11.5, -0.5) {};
\node [style={circulo_verde}] (17) at (11.5, -2) {};
\node [style={circulo_vermelho}] (18) at (15.5, 1) {};
\node [style={circulo_vermelho}] (19) at (15.5, -0.5) {};
\node [style={circulo_vermelho}] (20) at (15.5, -2) {};
\node [style={circulo_vermelho}] (21) at (19.5, 1) {};
\node [style={circulo_vermelho}] (22) at (19.5, -0.5) {};
\node [style={circulo_vermelho}] (23) at (19.5, -2) {};
\node [style={circulo_amarelo}] (24) at (23.25, 1) {};
\node [style={circulo_amarelo}] (25) at (23.25, -0.5) {};
\node [style={circulo_amarelo}] (26) at (23.25, -2) {};
\node [style=texto] (27) at (0, 6.75) {Static Input Layer};
\node [style=texto] (28) at (0, 6) {4 Units};
\node [style=texto] (29) at (3.5, 6.75) {Static Dense Layer};
\node [style=texto] (30) at (3.5, 6) {64 Units};
\node [style=texto] (31) at (7, 6.75) {Static Dense Layer};
\node [style=texto] (32) at (7, 6) {128 Units};
\node [style=texto] (33) at (0, -1.25) {LSTM Input Layer};
\node [style=texto] (34) at (0, -2) {24 Units};
\node [style=texto] (35) at (7, -1.25) {LSTM Layer};
\node [style=texto] (36) at (7, -2) {128 Units};
\node [style=texto] (37) at (11.5, 2.75) {Concatenate Layer};
\node [style=texto] (38) at (11.5, 2) {256 Units};
\node [style=texto] (39) at (15.5, 2.75) {Static Dense Layer};
\node [style=texto] (40) at (15.5, 2) {48 Units};
\node [style=texto] (41) at (19.5, 2.75) {Static Dense Layer};
\node [style=texto] (42) at (19.5, 2) {24 Units};
\node [style=texto] (43) at (23.25, 2.75) {Output Layer};
\node [style=texto] (44) at (23.25, 2) {12 Units};
\draw [style=seta] (0) to (3);
\draw [style=seta] (0) to (4);
\draw [style=seta] (0) to (5);
\draw [style=seta] (1) to (3);
\draw [style=seta] (1) to (4);
\draw [style=seta] (1) to (5);
\draw [style=seta] (2) to (3);
\draw [style=seta] (2) to (4);
\draw [style=seta] (2) to (5);
\draw [style=seta] (3) to (6);
\draw [style=seta] (3) to (7);
\draw [style=seta] (3) to (8);
\draw [style=seta] (4) to (6);
\draw [style=seta] (4) to (7);
\draw [style=seta] (4) to (8);
\draw [style=seta] (5) to (6);
\draw [style=seta] (5) to (7);
\draw [style=seta] (5) to (8);
\draw [style=seta] (9) to (12);
\draw [style=seta] (9) to (13);
\draw [style=seta] (9) to (14);
\draw [style=seta] (10) to (12);
\draw [style=seta] (10) to (13);
\draw [style=seta] (10) to (14);
\draw [style=seta] (11) to (12);
\draw [style=seta] (11) to (13);
\draw [style=seta] (11) to (14);
\draw [style=seta] (6) to (15);
\draw [style=seta] (6) to (16);
\draw [style=seta] (6) to (17);
\draw [style=seta] (7) to (15);
\draw [style=seta] (7) to (16);
\draw [style=seta] (7) to (17);
\draw [style=seta] (8) to (15);
\draw [style=seta] (8) to (16);
\draw [style=seta] (8) to (17);
\draw [style=seta] (12) to (15);
\draw [style=seta] (12) to (16);
\draw [style=seta] (12) to (17);
\draw [style=seta] (13) to (15);
\draw [style=seta] (13) to (16);
\draw [style=seta] (13) to (17);
\draw [style=seta] (14) to (15);
\draw [style=seta] (14) to (16);
\draw [style=seta] (14) to (17);
\draw [style=seta] (15) to (18);
\draw [style=seta] (15) to (19);
\draw [style=seta] (15) to (20);
\draw [style=seta] (16) to (18);
\draw [style=seta] (16) to (19);
\draw [style=seta] (16) to (20);
\draw [style=seta] (17) to (18);
\draw [style=seta] (17) to (19);
\draw [style=seta] (17) to (20);
\draw [style=seta] (18) to (21);
\draw [style=seta] (18) to (22);
\draw [style=seta] (18) to (23);
\draw [style=seta] (19) to (21);
\draw [style=seta] (19) to (22);
\draw [style=seta] (19) to (23);
\draw [style=seta] (20) to (21);
\draw [style=seta] (20) to (22);
\draw [style=seta] (20) to (23);
\draw [style=seta] (21) to (24);
\draw [style=seta] (21) to (25);
\draw [style=seta] (21) to (26);
\draw [style=seta] (22) to (24);
\draw [style=seta] (22) to (25);
\draw [style=seta] (22) to (26);
\draw [style=seta] (23) to (24);
\draw [style=seta] (23) to (25);
\draw [style=seta] (23) to (26);
\draw [style=seta, in=135, out=45, loop] (12) to ();
\draw [style=seta, in=135, out=45, loop] (13) to ();
\draw [style=seta, in=135, out=45, loop] (14) to ();
\end{tikzpicture}
\caption{Parallel LSTM-MLP network}
\label{fig:enter-label}
\end{figure}
\end{document}
输出:
这里有很多问题:
1 - 如果我尝试使用缩放整个图片scale = 0.5
,我仍然会得到Overfull \hbox (34.27876pt too wide) in paragraph at lines 140--141
2 - 每个节点上方重叠的文本;
3 - 在蓝色节点中,从这些节点开始和结束的箭头也与其上方的节点重叠(或者在第一个蓝色节点的情况下,它与文本重叠LSTM Layer 128 units
)。
关于如何解决这些问题有什么想法吗?
答案1
我不会缩放您的图片,因为结果图片的字体大小不一致,格式也不太准确。通过重新绘制图片可以获得更好的结果,我会这样做:
- 减少节点之间的水平距离
- 在节点中,用于层描述使用
\footnotesize
字体和文本分布在多行中 - 重命名节点,使其名称一致
<layer name><number of node>
。通过此更改,可以在双循环中绘制节点之间的箭头:
\documentclass[numbers, preprint, review,
12pt, sort&compress]{elsarticle}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum} % for dummy text
%---------------------------------------------------------------%
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[%scale=0.7, transform shape,
C/.style = {circle, draw, inner sep=0pt, minimum size=4mm},
Cin/.style = {C, fill=gray},
Cr/.style = {C, fill=red},
Cg/.style = {C, fill=green},
Cy/.style = {C, fill=yellow},
Cb/.style = {C, fill=blue},
Tx/.style = {font=\footnotesize\linespread{0.84}\selectfont, inner sep=0pt,
align=center, above},
every edge/.style= {draw=gray, -Straight Barb, semithick}
]
% nodes
\node [Cin] (I1) at (0, 5) {};
\node [Cin] (I2) at (0, 3.5) {};
\node [Cin] (I3) at (0, 2) {};
\node [Cr] (A1) at (2, 5) {};
\node [Cr] (A2) at (2, 3.5) {};
\node [Cr] (A3) at (2, 2) {};
\node [Cr] (B1) at (4, 5) {};
\node [Cr] (B2) at (4, 3.5) {};
\node [Cr] (B3) at (4, 2) {};
\node [Cg] (C1) at (6, 1) {};
\node [Cg] (C2) at (6, -0.5) {};
\node [Cg] (C3) at (6, -2) {};
\node [Cin] (D1) at (8, 1) {};
\node [Cin] (D2) at (8, -0.5) {};
\node [Cin] (D3) at (8, -2) {};
\node [Cin] (E1) at (10, 1) {};
\node [Cin] (E2) at (10, -0.5) {};
\node [Cin] (E3) at (10, -2) {};
\node [Cy] (O1) at (12, 1) {};
\node [Cy] (O2) at (12, -0.5) {};
\node [Cy] (O3) at (12, -2) {};
\node [Cr] (J1) at (0, -3) {};
\node [Cr] (J2) at (0, -4.5) {};
\node [Cr] (J3) at (0, -6) {};
\node [Cb] (G1) at (4, -3) {};
\node [Cb] (G2) at (4, -4.5) {};
\node [Cb] (G3) at (4, -6) {};
\node [Tx] at (0, 5.5) {Static\\ Input\\ Layer\\ 4 Units};
\node [Tx] at (2, 5.5) {Static\\ Dense\\ Layer\\ 64 Units};
\node [Tx] at (4, 5.5) {Static\\ Dense\\ Layer\\ 128 Units};
\node [Tx] at (0, -2) {LSTM\\ Input\\ Layer\\ 24 Units};
\node [Tx] at (4, -2) {LSTM\\ Layer\\ 128 Units};
\node [Tx] at (6, 2) {Concatenate\\ Layer\\ 256\\ Units};
\node [Tx] at (8, 2) {Static\\ Dense\\ Layer\\ 48 Units};
\node [Tx] at (10, 2) {Static\\ Dense\\ Layer\\ 24 Units};
\node [Tx] at (12, 2) {Output\\ Layer\\ 12 Units};
% arrows
\foreach \m in {1,2,3}
\foreach \n in {1,2,3}
{
\draw (I\m) edge (A\n)
(A\m) edge (B\n)
(B\m) edge (C\n)
(C\m) edge (D\n)
(D\m) edge (E\n)
(E\m) edge (O\n) % output
%
(J\m) edge (G\n)
(G\m) edge (C\n)
%
(G\n) edge [in=135, out=45, loop] ();
}
\end{tikzpicture}
\caption{Parallel LSTM-MLP network}
\label{fig:enter-label}
\end{figure}
\end{document}
如果图像太高,则减少节点之间的垂直距离(例如从 1.5 到 1,或者您希望的数值)
答案2
根据 Zarko 的答案。您可以使用 和 调整dx
间距dy
。
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{figure}
\begin{tikzpicture}[
C/.style = {circle, draw, inner sep=0pt, minimum size=4mm},
C1/.style = {C, fill=red}, C2/.style = {C, fill=blue},
C3/.style = {C, fill=green},C4/.style = {C, fill=gray},
C5/.style = {C, fill=gray}, C6/.style = {C, fill=yellow},
C7/.style = {C, fill=gray}, C8/.style = {C, fill=red},
C9/.style = {C, fill=red},
Tx/.style = {font=\footnotesize\linespread{0.84}\selectfont, inner sep=0pt,
align=center, above},
every edge/.style= {draw=gray, -Straight Barb, semithick} ]
\def\dx{2}
\def\dy{1.5}
\foreach \i/\j/\n/\lab [count=\ST] in {
0/0/J/{LSTM\\ Input\\ Layer\\ 24 Units},
2*\dx/0/G/{LSTM\\ Layer\\ 128 Units},
3*\dx/4/C/{Concatenate\\ Layer\\ 256\\ Units},
4*\dx/4/D/{Static\\ Dense\\ Layer\\ 48 Units},
5*\dx/4/E/{Static\\ Dense\\ Layer\\ 24 Units},
6*\dx/4/O/{Output\\ Layer\\ 12 Units},
0/8/I/{Static\\ Input\\ Layer\\ 4 Units},
\dx/8/A/{Static\\ Dense\\ Layer\\ 64 Units},
2*\dx/8/B/{Static\\ Dense\\ Layer\\ 128 Units}}
{\foreach \k in {1,2,3} {\node[C\ST](\n\k) at (\i,\j+\dy*\k) {};}
\node[anchor=south,above=2em,text width=2cm] at (\n3){\lab};
}
\foreach \m in {1,2,3}
\foreach \n in {1,2,3}
{ \draw (I\m) edge (A\n)
(A\m) edge (B\n)
(B\m) edge (C\n)
(C\m) edge (D\n)
(D\m) edge (E\n)
(E\m) edge (O\n)
(J\m) edge (G\n)
(G\m) edge (C\n)
(G\n) edge [in=135, out=45, loop] ();
}
\end{tikzpicture}
\caption{Parallel LSTM-MLP network}
\label{fig:enter-label}
\end{figure}
\end{document}