使用 Tikz 进行工作分解

使用 Tikz 进行工作分解

我正在尝试使用 tikz 创建工作分解结构。我希望所需结构

相反,我有以下内容:实际结果

这是我的代码:

\documentclass[tikz,border=10pt]{standalone}\usepackage{tikz}
\usetikzlibrary{shadows,arrows,positioning}
\usepackage{color,soul} %For highlighting
% Define the layers to draw the diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

% Define block styles
\tikzstyle{materia}=[draw, text width=6.0em, text centered,
  minimum height=1.5em]
\tikzstyle{etape} = [materia, text width=12em, minimum width=10em,
  minimum height=3em, rounded corners]
\tikzstyle{texto} = [above, text width=6em, text centered]
\tikzstyle{linepart} = [draw, thick, color=black!30, -latex', dashed]
\tikzstyle{line} = [draw, thick, color=black!30, -latex']
\tikzstyle{ur}=[draw, text centered, minimum height=0.01em]

% Define distances for bordering
\newcommand{\blockdist}{1.3}
\newcommand{\edgedist}{1.5}

\newcommand{\etape}[2]{node (p#1) [etape]
  {#2}}

\newcommand{\transreceptor}[3]{%
  \path [linepart] (#1.east) -- node [above]
    {\scriptsize #2} (#3);}

\begin{document}
\begin{tikzpicture}[scale=0.7,transform shape]

  % Draw diagram elements
  \path \etape{1}{\textbf{Operating Items}};
  \path (p1.west)+(-5.0,0.0)\etape{2}{\textbf{Non-Operating Items}};
  \path (p2.south)+(0.0,-1.0)\etape{3}{\textbf{Interest}};
  \path (p3.south)+(0.0,-1.0)\etape{4}{\textbf{Profits and Losses}};
  \path (p4.south)+(0.0,-1.0)\etape{5}{\textbf{Subsidies}};
  \path (p1.south)+(2.5,-1.0)\etape{6}{\textbf{Direct Operating Costs}};
  \path (p1.south)+(-2.5,-1.0)\etape{7}{\textbf{Indirect Operating Costs}};




  % Draw arrows between elements

  \path [line] (p2.south) -- node [above] {} (p3);
  \path [line] (p3.south) -- node [above] {} (p4);
  \path [line] (p4.south) -- node [above] {} (p5); 
  \path [line] (p1.south) -- +(0.0,-0.2) -- +(+2.5,-0.2)
   -- node [above, midway] {} (p6);
   \path [line] (p1.south) -- +(0.0,-0.2) -- +(-2.5,-0.2)
   -- node [above, midway] {} (p7);





\end{tikzpicture}
\end{document}

´´´

答案1

欢迎使用 TeX-SE!如果您的问题是关于对代码进行最小程度的破坏性修改,从而产生此类问题,这里有一个建议:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{shadows,arrows,positioning}
\usepackage{color,soul} %For highlighting
% Define the layers to draw the diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

% Define block styles
\tikzset{materia/.style={draw, text width=6.0em, text centered,
  minimum height=1.5em},
etape/.style={materia, text width=12em, minimum width=10em,
  minimum height=3em, rounded corners},
texto/.style={above, text width=6em, text centered},
linepart/.style={draw, thick, color=black!30, -latex', dashed},
line/.style={draw, thick, color=black!30, -latex'},
ur/.style={draw, text centered, minimum height=0.01em}}

% Define distances for bordering
\newcommand{\blockdist}{1.3}
\newcommand{\edgedist}{1.5}

\newcommand{\etape}[2]{node (p#1) [etape]
  {#2}}

\newcommand{\transreceptor}[3]{%
  \path [linepart] (#1.east) -- node [above]
    {\scriptsize #2} (#3);}

\begin{document}
\begin{tikzpicture}[scale=0.7,transform shape]

  % Draw diagram elements
  \path \etape{1}{\textbf{Operating Items}};
  \path (p1.west)+(-6.5,0.0)\etape{2}{\textbf{Non-Operating Items}};
  \path (p2.south)+(1,-1.0)\etape{3}{\textbf{Interest}};
  \path (p3.south)+(0.0,-1.0)\etape{4}{\textbf{Profits and Losses}};
  \path (p4.south)+(0.0,-1.0)\etape{5}{\textbf{Subsidies}};
  \path (p1.south)+(2.5,-1.0)\etape{6}{\textbf{Direct Operating Costs}};
  \path (p1.south)+(-2.5,-1.0)\etape{7}{\textbf{Indirect Operating Costs}};




  % Draw arrows between elements
  \foreach \X in {3,4,5}    
  {\path [line] (p2.-165) |- (p\X.west);}
  \path [line] (p1.south) -- +(0.0,-0.2) -- +(+2.5,-0.2)
   -- node [above, midway] {} (p6);
   \path [line] (p1.south) -- +(0.0,-0.2) -- +(-2.5,-0.2)
   -- node [above, midway] {} (p7);


\end{tikzpicture}
\end{document}

在此处输入图片描述

如果你问的是实现此输出的更简洁的代码,答案会大不相同。例如,在我看来,下面的代码已经更短更简单了。

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows,positioning}

% Define block styles
\tikzset{materia/.style={draw, text width=6.0em, text centered,
  minimum height=1.5em},
  etape/.style={materia, text width=12em, minimum width=10em,
  minimum height=3em, rounded corners},
line/.style={draw, thick, color=black!30, -latex'}}


\begin{document}
\begin{tikzpicture}[scale=0.7,transform shape]
\begin{scope}[nodes=etape,font=\bfseries]
 \node (p1) {Operating Items};
 \node[left=6.5cm of p1] (p2) {Non-Operating Items};
 \node[below=5mm of p2,xshift=8mm] (p3) {Interest};
 \node[below=5mm of p3] (p4) {Profits and Losses};
 \node[below=5mm of p4] (p5) {Subsidies};
 \node[below left=8mm and 1mm of p1.south] (p6) {Direct Operating Costs};
 \node[below right=8mm and 1mm of p1.south] (p7) {Indirect Operating Costs};
\end{scope}
% Draw arrows between elements
\foreach \X in {3,4,5}  
  {\path [line] (p2.-165) |- (p\X.west);}
\foreach \X in {6,7}    
  {\path [line] (p1.south) -- ++(0,-2mm) -| (p\X.north);}
\end{tikzpicture}
\end{document}

相关内容