tikz 节点对齐失败

tikz 节点对齐失败

在看似最简单的图表中,第一个节点不会与左侧对齐,而这正是我想要的。我尝试了很多次,只有将第二个节点从左侧更改为below left = of n1below = of n1一个节点时,其他节点才会移到右侧。

% -*- mode: latex; TeX-engine: luatex; coding: utf-8; -*-
\RequirePackage{kvoptions-patch}
\RequirePackage{scrlfile}
\RequirePackage{xpatch}
\listfiles
\documentclass[tikz,border=.5cm]{standalone}
\PreventPackageFromLoading{fixltx2e}
\PassOptionsToPackage{activate={true,nocompatibility},%
  expansion=true,protrusion=true}{microtype}
\usetikzlibrary{arrows,positioning,shapes.symbols,babel}
\usepackage[main=ngerman]{babel}
\usepackage{calc}
\usepackage[style=german]{csquotes}
\usepackage{float, ragged2e, mathtools, unicode-math, letltxmacro, luatextra}
\defaultfontfeatures{Ligatures={TeX,Common}}
\usepackage{microtype}
\begin{document}
\begin{tikzpicture}[every node/.style={align = flush left}]
  \node (n1) {Bestehende Angst"|störung vor traumatischem
    Erlebnis};
  \node [below left = of n1] (n2) {Angststörung};
  \node [draw, starburst, right=of n2] (n3) {Trauma};
  \node [right = of n3] (n4) {Verstärkung der be-\\stehenden
    Angststörung};
  \node [below = of n2, distance = 4ex] (n5) {Angststörung};
  \node [draw, starburst, right = of n5] (n6) {Trauma};
  \node [right = of n6] (n7) {Angststörung \textbf{und} PTBS
    \hphantom{b}};
  \node [below = of n5.west] (n8) {};
  \node [below = of n7.east] (n9) {};
  \draw [thick, ->] (n2) to (n3);
  \draw [thick, ->] (n3) to (n4);
  \draw [thick, ->] (n5) to (n6);
  \draw [thick, ->] (n6) to (n7);
  \draw [thick, ->] (n8.east) to (n9.west) node [below left] {Zeit};
\end{tikzpicture}
\end{document}

节点

答案1

看看以下解决方案是否适合您:

\documentclass[tikz,border=.5cm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,
                positioning,
                shapes.symbols,
                babel}
\usepackage[main=ngerman]{babel}
\makeatletter
\tikzset{suspend join/.code={\def\tikz@after@path{}}}
\makeatother

\begin{document}
    \begin{tikzpicture}[
node distance = 9mm and 12mm,
  start chain = going right,
   arr/.style = {-Stealth, semithick, shorten >=1mm, shorten <=1mm},
     N/.style = {align=left, inner sep=0pt, on chain, join=by arr},
     S/.style = {starburst, draw, outer sep=1mm, on chain, join=by arr},
                        ] 
%
\node (n11) [N] {Angststörung};
\node (n12) [S] {Trauma};
\node (n13) [N] {Verstärkung der be-\\stehenden Angststörung};
%
\node (n21) [N,suspend join,
             below=of n11 |- n12.south] {Angststörung};
\node (n22) [S] {Trauma};
\node (n23) [N] {Angststörung \textbf{und} PTBS};
% titl
\node[above=of n12] {Bestehende Angstörung vor traumatischem Erlebnis};
% zeit 
\coordinate[below=of n21.west |- n22.south] (aux);
\draw [arr] 
    (aux) -- (aux-| n23.east) node [below left] {Zeit};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

摘要:使用

\node [below = of n1.south west, anchor=north west] (n2) {Angststörung};

(以下是冗长的解释。)你有

 \node [below left = of n1] (n2) {Angststörung};

below left表示将 的右上角n2放置在 的左下角n1,x 和 y 方向的偏移量均由 定义node distance

你要做的是将 的左上角n2直接放在 的左下角下方n1。因此你首先需要

below = of n1.south west

您需要指定south west锚点,否则它将被放置在south锚点下方n1

其次你需要添加

anchor = north west

belowbelow将隐式设置anchor=north,并且必须覆盖该设置。如果您交换顺序(anchor=..., below=..),则该anchor设置将不会产生任何效果。

因此,\node [below = of n1.south west, anchor=north west] (n2) {Angststörung};您就可以得到您所需要的。

相关内容