(In order to ensure that each post should only focus on one key point, I have reformulated my question and provided the modified TikZ code. )For the problem How can I use straight lines to connect elements inside nested TikZ environments?, how to align?
1 Answer
Thanks @Explorer and @MS-SPO. Following the suggestions and assistance from @Explorer and @MS-SPO, we redesigned the TikZ diagram using a coordinate-based approach to ensure that all critical nodes are aligned at the (top) level.
The tikz:
\documentclass[border=5mm]{standalone}
\usepackage{ctex}
\usepackage{setspace}
\setstretch{1.5}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\begin{document}
\begin{tikzpicture}[
>=stealth,
foo/.style 2 args={draw,font=\bfseries,inner sep=5pt,minimum width=#1 cm,minimum height=#2 cm},
foo/.default={1}{0.8},
box/.style={draw,inner sep=8pt,rounded corners=2pt,minimum width=15cm,minimum height=2.5cm},
small/.style={draw,inner sep=3pt,minimum width=1cm,minimum height=0.6cm,font=\small}
]
\draw[help lines, gray!30] (-8, -18) grid (8, 8);
% coordinate axis
\draw[->, thin, red, dashed] (-8, 0) -- (8, 0) node[right] {x};
\draw[->, thin, red, dashed] (0, 8) -- (0, -18) node[below] {y};
% Automatically label all integers on the x-axis (from -8 to 8)
\foreach \x in {-8,...,8}
\node[below, gray, font=\tiny] at (\x, 0) {\x};
% Automatically label all integers on the y-axis (from -18 to 8)
\foreach \y in {-18,...,8}
\node[left, gray, font=\tiny] at (0, \y) {\y};
\coordinate (box_center) at (0, 7);
% first part
\node[foo] (O) at (box_center) {研究主题};
\node[foo] (A) at (-4, 7) {已有研究};
\node[foo] (B) at (4, 7) {理论基础};
\draw[->] (A) -- (O);
\draw[->] (B) -- (O);
% second part
\node[small] (X_o) at (0,3.5) {布朗运动};
\node[small] (X_a) at (-4,3.5) {期权定价};
\node[small] (X_b) at (4,3.5) {碳交易减排};
\node[small] (X_c) at (0,1.5) {分数布朗运动};
\node[small] (X_d) at (-4,5) {随机波动率};
\node[small] (X_e) at (-4,0.5) {DFP定价};
\draw[->] (X_d) -- (X_a);
\draw[<-] (X_a) -- (X_o);
\draw[<-] (X_b) -- (X_o);
\draw[<-] (X_c) -- (X_o);
\draw[<-] (X_e) -- (X_a);
\draw[->] (X_c) -| ([xshift=1.2em]X_a.south);
\draw[->] (X_c) -| (X_b.south);
\node[box] (X_box) [fit=(X_o)(X_a)(X_b)(X_c)(X_d)(X_e)] at (0, 3) {};
\node[font=\bfseries,anchor=north] at (X_box.north) {文献研究};
\draw[<-] (X_box.north) -- (O);
% third part
\node[small,text width=5em,align=center,anchor=north] (Y_o) at (0,-1) {考虑交易费用的欧式期权定价问题};
\node[small,text width=5em,align=center,anchor=north] (Y_a) at (0,-3.5) {考虑交易费用的回望期权定价问题};
\node[small,text width=5em,align=center,anchor=north] (Y_dfp) at (0,-6) {DFP定价问题};
\node[small,text width=1em,align=center] (Y_c) [left=0.3cm of Y_a] {参数校准};
\node[small,text width=1em,align=center,anchor=north] (Y_d) [right=0.3cm of Y_a] {参数敏感性分析};
\node[small,text width=3em,align=center,anchor=north] (Y_e) at (-4,-1) {布朗运动};
\node[small,text width=3em,align=center,anchor=north] (Y_i) at (-4,-3.5) {分数布朗运动};
\node[small,text width=1em,align=center,anchor=north] (Y_j) at (-4.7,-6) {期权定价};
\node[small,text width=1em,align=center,anchor=north] (Y_k) at (-3.3,-6) {碳交易减排};
\node[small,text width=3em,align=center,anchor=north] (Y_f) at (4,-1) {碳交易减排策略};
\node[small,text width=3em,align=center,anchor=north] (Y_g) at (4,-3.5) {参数校准};
\node[small,text width=3em,align=center,anchor=north] (Y_h) at (4,-6) {参数敏感性分析};
\draw[-] (Y_o) -- (Y_a);
\draw[-] (Y_a) -- (Y_dfp);
\draw[-] (Y_c.north) |- (Y_o.west);
\draw[-] (Y_c.east) -- (Y_a.west);
\draw[-] (Y_d.north) |- (Y_o.east);
\draw[-] (Y_d.west) -- (Y_a.east);
\draw[-] (Y_dfp.west) -| (Y_c.south);
\draw[-] (Y_dfp.east) -| (Y_d.south);
\draw[-] (Y_e) -- (Y_i);
\draw[-] ([xshift=-0.3em]Y_i.south) -- ++(0,-0.5) -| (Y_j.north);
\draw[-] ([xshift=0.3em]Y_i.south) -- ++(0,-0.5) -| (Y_k.north);
\draw[-] (Y_f) -- (Y_g);
\draw[-] (Y_g) -- (Y_h);
\node[box] (Y_box) [fit=(Y_o)(Y_a)(Y_dfp)(Y_c)(Y_d)(Y_e)(Y_i)(Y_j)(Y_k)(Y_f)(Y_g)(Y_h)] at (0,-4.7) {};
\node[anchor=east,text width=1em,font=\linespread{1.}\bfseries] at (Y_box.east) {问题分析};
\draw[<-] (Y_box.north) -- (X_box.south);
% fourth part
\node[small,text width=4em,align=center,anchor=north] (Z_o) at (0, -10) {对冲策略};
\node[small,text width=4em,align=center,anchor=north] (Z_hedge) at (-4,-10) {对冲策略、HJB方程};
\node[small,text width=4em,align=center,anchor=north] (Z_f) at (4,-10) {HJB方程};
\node[box] (Z_box) [fit=(Z_hedge)(Z_o)(Z_f)] at (0,-10.5) {};
\node[font=\linespread{1.}\bfseries,anchor=east,text width=1em,] at (Z_box.east) {研究方法};
\draw[->] (Y_dfp.south) -- (Z_o.north);
\draw[<-] (Z_f) -- (Y_h);
\draw[<-] ([xshift=-0.3em]Z_hedge.north) -- ++(0,0.5) -| (Y_j.south);
\draw[<-] ([xshift=0.3em]Z_hedge.north) -- ++(0,0.5) -| (Y_k.south);
% fifth part
\node[small,text width=7em,align=center,anchor=north] (U_o) at (0,-12.5) {(\textbf{第三、四、五章})\\考虑交易费用的期权以及DFP定价、参数校准、参数敏感性分析};
\node[small,text width=6em,align=center,anchor=north] (U_g) at (-4,-12.5) {(\textbf{第二章})\\已有研究成果、理论的梳理,研究空间挖掘};
\node[small,text width=6em,align=center,anchor=north] (U_f) at (4,-12.5) {(\textbf{第六章})\\碳交易减排策略、参数校准、参数敏感性分析};
\node[box] (U_box) [fit=(U_g)(U_o)(U_f)] at (0,-14) {};
\node[font=\linespread{1.}\bfseries,anchor=east,text width=1em,] at (U_box.east) {研究内容};
\draw[->] (Z_hedge.south) -- (U_g.north);
\draw[->] (Z_o.south) -- (U_o.north);
\draw[->] (Z_f.south) -- (U_f.north);
\node[foo] (Z) [below=1cm of U_o] {\textbf{第七章:结论、管理启示、展望}};
\draw[<-] (Z.north) -- (U_box.south);
\end{tikzpicture}
\end{document}
The screenshot:
