You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用LaTeX TikZ实现带左侧向下分支的流程图?

问题描述

我尝试用LaTeX绘制如图所示的流程图,但不知道如何制作向左下方延伸的框体。现附上我目前编写到一半的代码,恳请提供帮助:

流程图示意图

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows} 
\usetikzlibrary{positioning}    

\begin{document}
    \begin{tikzpicture}[
        > = latex',
        every node/.style={
            draw,
            minimum width=2cm,
            minimum height=0.8cm,
        },
    ]
%
\node (S1) {Step 1};
%
\node[below=of S1] (S2) {Step 2};
\node[below=of S1, left=of S2] (S3) {Step 3};
\node[below=of S1, right=of S2] (S4) {Step 4};

\node[below=of S2] (S2a) {Step 2a};
\node[below=of S3] (S3a) {Step 3a};
\node[below=of S4] (S4a) {Step 4a};

\node[below=of S2a] (S2b) {Step 2b};
\node[below=of S3a] (S3b) {Step 3b};
\node[below=of S4a] (S4b) {Step 4b};

\node[below=of S2b] (S2c) {Step 2c};
\node[below=of S3b] (S3c) {Step 3c};
\node[below=of S4b] (S4c) {Step 4c};


\node[below=of S2c] (S2d) {Step 2d};
\node[below=of S3c] (S3d) {Step 3d};
\node[below=of S4c] (S4d) {Step 4d};


\draw[->] 
(S1) edge (S2)
(S2) edge (S3);

\end{tikzpicture}
\end{document}
解决方案

要实现向左下方延伸的框体,你可以调整节点的定位方式,同时修正箭头连接逻辑。以下是修改后的完整代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows} 
\usetikzlibrary{positioning}    

\begin{document}
    \begin{tikzpicture}[
        > = latex',
        every node/.style={
            draw,
            minimum width=2cm,
            minimum height=0.8cm,
        },
        node distance=0.8cm and 1cm % 统一节点间距:上下0.8cm,左右1cm
    ]
% 起始节点
\node (S1) {Step 1};

% 第一层分支:直接定位到S1的正下方、左下方、右下方
\node[below=of S1] (S2) {Step 2};
\node[below left=of S1] (S3) {Step 3};
\node[below right=of S1] (S4) {Step 4};

% 各分支向下延伸
\node[below=of S2] (S2a) {Step 2a};
\node[below=of S3] (S3a) {Step 3a};
\node[below=of S4] (S4a) {Step 4a};

\node[below=of S2a] (S2b) {Step 2b};
\node[below=of S3a] (S3b) {Step 3b};
\node[below=of S4a] (S4b) {Step 4b};

\node[below=of S2b] (S2c) {Step 2c};
\node[below=of S3b] (S3c) {Step 3c};
\node[below=of S4b] (S4c) {Step 4c};

\node[below=of S2c] (S2d) {Step 2d};
\node[below=of S3c] (S3d) {Step 3d};
\node[below=of S4c] (S4d) {Step 4d};

% 箭头连接:完善所有分支的流向
\draw[->] 
(S1) edge (S2)
(S1) edge (S3)
(S1) edge (S4)
(S2) edge (S2a)
(S3) edge (S3a)
(S4) edge (S4a)
(S2a) edge (S2b)
(S3a) edge (S3b)
(S4a) edge (S4b)
(S2b) edge (S2c)
(S3b) edge (S3c)
(S4b) edge (S4c)
(S2c) edge (S2d)
(S3c) edge (S3d)
(S4c) edge (S4d);

\end{tikzpicture}
\end{document}

关键修改点:

  • 用below left=of S1直接将S3定位到S1的左下方,替代原代码中below=of S1, left=of S2的间接定位,更贴合左下方延伸的需求;
  • 添加node distance参数统一节点间距,让流程图布局更规整;
  • 修正原代码中错误的S2 edge (S3)连接逻辑,补全所有分支的箭头,完善流向;
  • 新增S1到S4的箭头,完整呈现三分支结构。

内容的提问来源于stack exchange,提问作者bvowe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 04:57:19