
저는 수업을 사용하고 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}