我想在 Tikz 中创建附图。
由于我对 tikz 还很陌生,我不知道该使用什么以及如何开始。
因为它有一些复杂的线条和箭头。欢迎提出任何建议
答案1
这是另一个diag.tex
:
\documentclass{article}
\usepackage[inline]{asymptote}
\usepackage{lmodern}
\begin{document}
\begin{figure}
\begin{asy}
size(400);
pair O=(0,0);
// triangle
pair[] ptriangle={(-186,-92),(186,-92),(0,185),};
pen penT=darkblue+1bp;
pen penEl=orange+1bp+linetype(new real[] {5,3,2,3});
// draw triangle
draw(ptriangle[0]--ptriangle[1]--ptriangle[2]--cycle,penT);
// a fucntion to draw an ellipse defined by the center and x- and y-scale factors
void ellipse(pair center,real xs,real ys,pen p=currentpen){
draw(shift(center)*scale(xs,ys)*unitcircle,p);
};
ellipse(ptriangle[2],255,120,penEl);
ellipse(ptriangle[0],180,140,penEl);
ellipse(ptriangle[1],180,140,penEl);
guide[] thickArr={
(-147,161)..(-224,68)..(-210,-38),
(206,159)..(280,67)..(264,-34),
(-105,-157)..(-4,-208)..(95,-168),
};
pen squarecap=linecap(0);
pen roundcap=linecap(1);
pen extendcap=linecap(2);
pen dashed=squarecap+linetype(new real[] {1.5,1.5}); // set up dashed pattern
pen penThickArr=dashed+2bp;
pen penThinArr=red+extendcap;
for(int i=0;i<thickArr.length;++i){
draw(thickArr[i], penThickArr,Arrows(size=5));
}
guide[] thinArr={
(-68,-35)--(67,-35),
(69,-12)--(10,99),
(-8,101)--(-67,-13),
};
for(int i=0;i<thickArr.length;++i){
draw(thinArr[i], penThinArr,Arrows);
}
string[] planeLabel={"MNE","Subsidiary 1","HQ","Subsidiary 2"};
pair[] planeLabelPos={(0,40),(143,-58),(2,106),(-149,-57)};
pair[] planeLabelAlign={
O,W,N,E
};
defaultpen(fontsize(10pt));
for(int i=0;i<planeLabel.length;++i){
label(planeLabel[i],planeLabelPos[i],planeLabelAlign[i]);
}
pair[] listLabelPos={(0,235),(187,-149),(-210,-142)};
string[] listLabel={
minipage("\textit{Home Country Context}"
+"\begin{itemize}"
+"\item Resources"
+"\item Institutions"
+"\end{itemize}"
,width=120pt),
minipage("\textit{Host Context 1}"
+"\begin{itemize}"
+"\item Resources"
+"\item Institutions"
+"\end{itemize}"
,width=100pt),
minipage("\textit{Host Context 2}"
+"\begin{itemize}"
+"\item Resources"
+"\item Institutions"
+"\end{itemize}"
,width=100pt),
};
pair[] listLabelAlign={O,O,O};
for(int i=0;i<listLabel.length;++i){
label(listLabel[i],listLabelPos[i],listLabelAlign[i]);
}
\end{asy}
\end{figure}
\end{document}
为了处理它latexmk
,请创建文件latexmkrc
:
sub asy {return system("asy '$_[0]'");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");
然后运行latexmk -pdf diag.tex
。
答案2
一种可能性,仍然可以改进:
\documentclass{article}
\usepackage{enumitem}
\usepackage{varwidth}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,shapes.geometric,fit}
\newcommand\NText[1]{%
\begin{varwidth}[t]{10cm}
\textit{#1}\\[-2ex]
\begin{itemize}[nolistsep]
\item Resources
\item Institutions
\end{itemize}
\end{varwidth}%
}
\begin{document}
\begin{tikzpicture}
\node at (-2.25,0) (sub2) {Subsidiary 2};
\node at (2.25,0) (sub1) {Subsidiary 1};
\node at ([yshift=-2cm] $ (-2.25,0) + (60:5cm) $ ) (hc) {HQ};
\node at (barycentric cs:sub1=0.5,sub2=0.5,hc=0.7) {MNE};
\node[align=left,below left= 20pt and -1cm of sub2]
(con2) {\NText{Host Context 2}};
\node[draw,dashdotted,ellipse,fit=(sub2)(con2)] (fit2) {};
\node[align=left,below right= 20pt and -1cm of sub1]
(con1) {\NText{Host Context 1}};
\node[draw,dashdotted,ellipse,fit=(sub1)(con1)] (fit1) {};
\node[align=left,above= 20pt of hc]
(con3) {\NText{Home Country Context}};
\node[draw,dashdotted,ellipse,fit=(hc)(con3)] (fit3) {};
\draw
([yshift=0.5cm]hc.north) --
([xshift=0.8cm,yshift=-0.5cm]sub1.east) --
([xshift=-0.8cm,yshift=-0.5cm]sub2.west) --
([yshift=0.5cm]hc.north);
\coordinate (aux1) at ([xshift=-0.25cm,yshift=0.25cm]sub1.north);
\coordinate (aux2) at ([xshift=0.25cm,yshift=0.25cm]sub2.north);
\draw[<->,line width=1pt] (hc) -- (aux1);
\draw[<->,line width=1pt] (hc) -- (aux2);
\draw[<->,line width=1pt] ([xshift=-10pt,yshift=-5pt]aux1.west) -- ([xshift=10pt,yshift=-5pt]aux2.east);
\draw[<->,dashed,line width=3pt]
([yshift=-20pt]fit1.north east)
to[bend right]
([xshift=-20pt]fit3.east);
\draw[<->,dashed,line width=3pt]
([yshift=-20pt]fit2.north west)
to[bend left]
([xshift=20pt]fit3.west);
\draw[<->,dashed,line width=3pt]
([xshift=-25pt]fit2.south east)
to[bend right]
([xshift=25pt]fit1.south west);
\end{tikzpicture}
\end{document}