Tikz 在多行上左对齐节点文本

Tikz 在多行上左对齐节点文本

因此,出于某种原因,即使使用 &,多行文本也不会左对齐,我不明白为什么。有人能给我一些提示吗?

在此处输入图片描述

\documentclass{minimal}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usetikzlibrary{matrix, calc, arrows}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[
    scale=5,
    axis/.style={very thick, ->, >=stealth'},
    important line/.style={thick},
    dashed line/.style={dashed, thin},
    pile/.style={thick, ->, >=stealth', shorten <=2pt, shorten
    >=2pt},
    every node/.style={color=black}
    ]
    % axis
    %\draw[axis] (-0.1,0)  -- (1.1,0) node(xline)[right]
        
    %\draw[axis] (0,-0.1) -- (0,1.1) node(yline)[above] {$C$};
    % Lines
    
    \matrix[matrix of math nodes,column sep={120pt,between origins},row
    sep={120pt,between origins},nodes={asymmetrical rectangle  }, ] (s)
  {
    &|[name=ka]|\begin{aligned}
         &C=0.30\\
         &N=10
      \end{aligned}&|[name=kb]|\begin{aligned}
         &C=0.30\\
         &N=20
      \end{aligned} &|[name=kc]|  \begin{aligned}
         &C=0.30\\
         &N=40
      \end{aligned} \\
    %
    &|[name=A]| \begin{aligned}
         &C=0.40\\
         &N=10
      \end{aligned} &|[name=B]|  \begin{aligned}
         &C=0.40\\
         &N=20
      \end{aligned}  &|[name=C]| \begin{aligned}
         &C=0.40\\
         &N=40
      \end{aligned}  &|[name=01]|  \\
    %
    |[name=02]|  &|[name=A']|  \begin{aligned}
         &C=0.45\\
         &N=10
      \end{aligned} &|[name=B']|  \begin{aligned}
         &C=0.45\\
         &N=20
      \end{aligned}  &|[name=C']|  \begin{aligned}
         &C=0.45\\
         &N=40
      \end{aligned}  \\
    %
  % &|[name=ca]| \coker f &|[name=cb]| \coker g &|[name=cc]| \coker h \\
  };
  \draw[->] (ka) edge (A)
            (kb) edge (B)
            (kc) edge (C)
            (A) edge (B)
            (B) edge  (C)
            %(C) edge (01)
            (A) edge  (A')
            (B) edge  (B')
            (C) edge  (C')
            %(02) edge (A')
            (A') edge  (B')
            (B') edge (C')
            %(A') edge (ca)
            %(B') edge (cb)
            %(C') edge (cc)
            (ka) edge (kb)
                 (kb) edge (kc)
  ;
 % \draw[->,gray] (ka) edge (kb)
  %               (kb) edge (kc)
  %               (ca) edge (cb)
  %               (cb) edge (cc)
  %;
 % \draw[->,gray,rounded corners] (kc) -| node[auto,text=black,pos=.7]
 %   {\(\partial\)} ($(01.east)+(.5,0)$) |- ($(B)!.35!(B')$) -|
 %   ($(02.west)+(-.5,0)$) |- (ca);
   
 
\end{tikzpicture}
\end{document}

答案1

不完全是最小例如,不是吗?;-)

无论如何,问题在于matrix改变了 的含义。因此,您可以按照手册中第 323 页左右的说明&使用 键,这样您就可以得到 表示 ,而表示数学 的不同。ampersand replacement\&matrix&aligned

% this is a (more) minimal example
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usetikzlibrary{matrix, calc, arrows}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[
    ]
    \matrix[matrix of math nodes,column sep={120pt,between origins},row
    sep={120pt,between origins},nodes={asymmetrical rectangle  }, 
    ampersand replacement=\&] (s)
  {
    \&|[name=ka]|\begin{aligned}
         &C=0.30\\
         &N=10
      \end{aligned} 
    \&|[name=kb]|\begin{aligned}
         &C=0.30\\
         &N=20
      \end{aligned} \\
  };
  \draw[->] (ka) edge (kb);
\end{tikzpicture}
\end{document}

在此处输入图片描述

另外,请注意已\usetikzlibrary{arrows}被弃用,您应该使用arrows.meta

相关内容