我正在尝试在 Tikz 中重新创建以下内容,但下面的代码没有运行 - 它挂起并且没有完成。我在使用 Tikz 时有点挣扎,并开始思考它。我需要为我的论文绘制大量图表,这只是其中之一……
我迄今为止的代码....
\documentclass[11pt]{report}
%% Package for creating diagrams
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning, fit, backgrounds, matrix, shadows, arrows.meta, positioning, chains, scopes}
\tikzset{
1/.style={fill=red!30},
2/.style={fill=blue!30},
3/.style={fill=orange!30},
4/.style={fill=green!30},
5/.style={fill=red},
arrow/.style={thick,->,>=stealth},
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\matrix(m)[matrix of nodes,column sep=0.75cm, row sep=0.5cm,
nodes={rectangle, rounded corners, text width=2.5cm, minimum height=1cm,text centered, draw=black,anchor=west},
]{
\node[draw=none](int){}; & \node[1](model){Socio-technical theory or model};\\
\node[1](social-methods){Social Methods} & \node[1](technical-methods){Technical Methods};\\
\node[1](social-data){Social Data} & \node[1](technical-data){Technical Data};\\
\node[draw=none](int){}; & \node[1](socio-analysis){Socio-technical analysis};\\
};
\end{tikzpicture}
\caption{A conceptual model for socio-technical research (reproduced from ...) }
\label{fig:socio-technical model}
\end{figure}
\end{document}
答案1
当您使用 时matrix of nodes
,矩阵中的节点不再需要\node{...};
包装器。修复此问题并添加一些元素(使用来自你最近的问题关于事情应该是什么样子)导致
\documentclass[11pt]{report}
%% Package for creating diagrams
\usepackage{tikz}
\usetikzlibrary{positioning,fit,matrix, backgrounds}
\tikzset{
1/.style={fill=red!30},
2/.style={fill=blue!30},
3/.style={fill=orange!30},
4/.style={fill=green!30},
5/.style={fill=red},
arrow/.style={thick,->,>=stealth},
back group/.style={fill=yellow!20,rounded corners, draw=black!50, dashed, inner xsep=15pt, inner ysep=10pt},
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[box/.style={rectangle, rounded corners,
text width=2.5cm, minimum height=1cm,text centered, draw=black},
font=\sffamily]
\matrix(m)[matrix of nodes,column sep=3.5em, row sep=0.5cm,nodes={box,
anchor=center},row 1/.style={nodes={2}},
row 2/.style={nodes={3}},row 3/.style={nodes={4}},]
(mat){
Social Methods & Technical Methods\\
Social Data & Technical Data\\
Social Analysis & Technical analysis\\
};
\begin{scope}[on background layer,nodes={back group}]
\node[fit=(mat-1-1)(mat.north-|mat-1-1)(mat.south-|mat-1-1),inner
xsep=1em,inner ysep=1.5em,draw,yshift=1ex,
label={[anchor=north west]north west:Social design}](F1){};
\node[fit=(mat-1-2)(mat.north-|mat-1-2)(mat.south-|mat-1-2),inner
xsep=1em,inner ysep=1.5em,draw,yshift=1ex,
label={[anchor=north west]north west:Technical design}](F2){};
\end{scope}
\node[box,above=3em of mat,text width=3.2cm,minimum height=1.3cm,1](model)
{Socio-technical theory or model};
\begin{scope}[arrow]
\foreach \X in {1,2}
{\draw (model) -- (F\X);
\draw (mat-1-\X) -- (mat-2-\X);
\draw (mat-2-\X) -- (mat-3-\X);
}
\draw (mat-3-1.east) -- ([yshift=-1em]mat-3-1.east-|F1.east);
\draw (mat-3-2.west) -- ([yshift=-1em]mat-3-2.west-|F2.west);
\draw (mat-1-2) -- (mat-2-1);
\end{scope}
\end{tikzpicture}
\caption{A conceptual model for socio-technical research (reproduced from
\dots).}
\label{fig:socio-technical model}
\end{figure}
\end{document}
答案2
在此代码片段的第二行和第三行中,您的代码在 & 之前缺少一个分号。因此,请将其更改:
\node[draw=none](int){}; & \node[1](model){Socio-technical theory or model};\\
\node[1](social-methods){Social Methods} & \node[1](technical-methods){Technical Methods};\\
\node[1](social-data){Social Data} & \node[1](technical-data){Technical Data};\\
\node[draw=none](int){}; & \node[1](socio-analysis){Socio-technical analysis};\\
更改为:
\node[draw=none](int){}; & \node[1](model){Socio-technical theory or model};\\
\node[1](social-methods){Social Methods}; & \node[1](technical-methods){Technical Methods};\\
\node[1](social-data){Social Data}; & \node[1](technical-data){Technical Data};\\
\node[draw=none](int){}; & \node[1](socio-analysis){Socio-technical analysis};\\
并呈现: