文本节点表现不佳

文本节点表现不佳

我正在尝试重新创建这个图像在此处输入图片描述

到目前为止我已经得到了这个。 在此处输入图片描述

右侧框中的文本只有 3 行,这很奇怪。我尝试增加文本宽度选项。但是这不是一个好选择,左侧框也变得很大,这是我不想要的。

请帮我创建这个(几乎)图像。

    \documentclass[border=10pt,tikz]{standalone}
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}
    \usepackage{tikz}
    \usetikzlibrary{trees,positioning,shapes,shadows,arrows}
    \begin{document}
    
    \tikzset{
      basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
      root/.style   = {basic, rounded corners=2pt, thin, align=center, fill=white},
      level-2/.style = {basic, rounded corners=3pt, thin,align=left, fill=white, text width=7cm},
      level-3/.style = {basic, thin, align=center, fill=white, text width=1.8cm}
    }
    
    
    \begin{tikzpicture}[
      level 1/.style={sibling distance=30em, level distance=5em},
    %   {edge from parent fork down},
      edge from parent/.style={->,solid,black,thick,sloped,draw}, 
      edge from parent path={(\tikzparentnode.south) -- (\tikzchildnode.north)},
      >=latex, node distance=1.2cm, edge from parent fork down]
      \node[root] (A) at (0,2)  {$AX=0$};
      \draw[->] (A) to (0,.3);
     \node[root] {\textbf{Always consistent}} 
      child {node[level-2] (c1) {\textbf{rank $A=n$} \\ \textbf{Unique Solution $X=0$}}}
      child {node[level-2] (c1) {\textbf{rank $A<n$} \\ \textbf{Infinitely many Solutions \\ $n-r$ arbitrary parameters in solution}}}
      ;
    \end{tikzpicture}  
    \end{document}

答案1

另一种解决方案是使用\usetikzlibrary{calc}

树 v01

\documentclass[border=5pt]{standalone}

\usepackage{tikz}

\usetikzlibrary{calc}

\usepackage{makecell}

\tikzstyle{orangenode}=[draw=black,minimum height=1cm,minimum width=4cm,fill=myorange]
\tikzstyle{bluenode}=[draw=black,minimum height=1cm,minimum width=4cm,fill=myblue]


\begin{document}
    \begin{tikzpicture}
        \definecolor{myorange}{RGB}{249,205,153}
        \definecolor{myblue}{RGB}{151,173,172}
        
        %first system
        
        %draw nodes
        \node(a0) [orangenode] at (0,0) {$ \mathbf{AX=0} $};
        \node(a1) [bluenode,anchor=north] at ($ (a0.south) - (0,1) $) {always consistent};
        \node(a21) [bluenode,anchor=north] at ($ (a1.south west) - (1,1) $) {\makecell[l]{Unique solution: $ \mathbf{X=0} $ \\ $ \mathrm{rank(\textbf{A})=n} $}};
        \node(a22) [bluenode,anchor=north] at ($ (a1.south east) + (1,-1) $) {\makecell[l]{Infinity of solutions: $ \mathbf{X=0} $ \\ $ \mathrm{rank(\textbf{A})<n} $ \\ $ \mathrm{n-r} $ arabitrary \\ parameters in solution}};
        
        %draw arrows
        \draw[-stealth] (a0.south) -- (a1.north);
        \draw[-stealth] (a1.south) --++ (0,-0.5cm);
        \draw[-stealth] (a1.south) --++ (0,-0.5cm) -| (a21.north);
        \draw[-stealth] (a1.south) --++ (0,-0.5cm) -| (a22.north);
        
        %second system
        
        %draw nodes
        \node(b0) [orangenode,anchor=north] at ($ (a22.south)!0.5!(a21.south) - (0,1.5)$) {$ \mathbf{AX=B, B \neq 0} $};
        \node(b11) [bluenode,anchor=north] at ($ (b0.south west) - (1,1) $) {\makecell[l]{Consistent: \\ $ \mathrm{rank(\textbf{A})=rank(\textbf{A|B})} $}};
        \node(b12) [bluenode,anchor=north] at ($ (b0.south east) + (1,-1) $) {\makecell[l]{Inconsistent: \\ $ \mathrm{rank(\textbf{A})<rank(\textbf{A|B})} $}};
        \node(b21) [bluenode,anchor=north] at ($ (b11.south west) - (1,1) $) {\makecell[l]{Unique Solution: \\ $ \mathrm{rank(\textbf{A})=n} $}};
        \node(b22) [bluenode,anchor=north] at ($ (b11.south east) + (1,-1) $) {\makecell[l]{Infinity of Solutions: \\ $ \mathrm{rank(\textbf{A})<n,} $ \\ $ \mathrm{n-r} $ arbitrary \\  parameters in solution}};
        
        %draw arrows
        \draw[-stealth] (b0.south) --++ (0,-0.5cm);
        \draw[-stealth] (b0.south) --++ (0,-0.5cm) -| (b11.north);
        \draw[-stealth] (b0.south) --++ (0,-0.5cm) -| (b12.north);
        \draw[-stealth] (b11.south) --++ (0,-0.5cm);
        \draw[-stealth] (b11.south) --++ (0,-0.5cm) -| (b21.north);
        \draw[-stealth] (b11.south) --++ (0,-0.5cm) -| (b22.north);
        
    \end{tikzpicture}
\end{document}

答案2

编辑: 添加了第二棵树形图的代码,数学运算符“rank”的定义,稍微改进了代码。

该包的使用forest很简单:

\documentclass[border=10pt, preview]{standalone}
\usepackage{mathtools}            % <---
\DeclareMathOperator{\rank}{rank} % <---
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,
                shadows}

\begin{document}
    \begin{forest}
for tree = {
% nodes
    draw, semithick,% rounded corners,
    minimum width = 4em, 
if level = 0{fill=orange!30}{fill = teal!30, text width=34mm},
    drop shadow,
    font = \sffamily\small\linespread{0.84}\selectfont,
% tree
     grow = south,
   anchor = north,
    forked edge,        % for forked edge
    edge  = {-Stealth},
    s sep = 2mm,    % sibling distance
    l sep = 8mm,    % level distance
 fork sep = 4mm,    % distance from parent to branching point
            }
[$\mathbf{AX=0}$,
    [Always consistent
        [{$\rank(\mathbf{A})=n$}    \\  \smallskip
         Unique Solution {$X=0$}]
        [{$\rank(\mathbf{A})<n$}    \\  \smallskip
         {Infinitely many Solutions,} 
         $n-r$ arbitrary parameters 
         in solution]
    ]
]
\end{forest}

\medskip
    \begin{forest}
for tree = {
% nodes
    draw, semithick,% rounded corners,
    minimum width = 4em,
if level = 0{fill=orange!30}{fill = teal!30, text width=36mm},
    drop shadow,
    font = \sffamily\small\linespread{0.84}\selectfont,
% tree
     grow = south,
   anchor = north,
    forked edge,        % for forked edge
    edge  = {-Stealth},
    s sep = 2mm,    % sibling distance
    l sep = 8mm,    % level distance
 fork sep = 4mm,    % distance from parent to branching point
            }
[$\mathbf{AX=B, B \neq 0}$;
    [Consistent: \\ 
     ${\rank(\mathbf{A})=\rank(\mathbf{A|B})}$
            [Unique Solution: \\ 
             {$\rank(\mathbf{A})=n$}]
            [Infinity of Solutions: \\
             {$\rank(\mathbf{A})<n$,} \\ 
             $n-r$ arbitrary parameters in solution]
    ]       
    [Inconsistent: \\ 
     $\rank(\mathbf{A})<\rank(\mathbf{A|B})$]
]
    \end{forest}
\end{document}

在此处输入图片描述

答案3

yshift=<value>可以手动调整树的子项。

 \documentclass[border=10pt,tikz]{standalone}
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}
    \usepackage{tikz}
    \usetikzlibrary{trees,positioning,shapes,shadows,arrows}
    \begin{document}
    
    \tikzset{
      basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
      root/.style   = {basic, rounded corners=2pt, thin, align=center, fill=white},
      level-2/.style = {basic, rounded corners=3pt, thin,align=left, fill=white, text width=7cm},
      level-3/.style = {basic, thin, align=center, fill=white, text width=1.8cm}
    }
    
    
    \begin{tikzpicture}[
      level 1/.style={sibling distance=30em, level distance=5em},
    %   {edge from parent fork down},
      edge from parent/.style={->,solid,black,thick,sloped,draw}, 
      edge from parent path={(\tikzparentnode.south) -- (\tikzchildnode.north)},
      >=latex, node distance=1.2cm, edge from parent fork down]
      \node[root] (A) at (0,2)  {$AX=0$};
      \draw[->] (A) to (0,.3);
     \node[root] {\textbf{Always consistent}} 
      child {node[level-2] (c1) {\textbf{rank $A=n$} \\ \textbf{Unique Solution $X=0$}}}
      child {node[level-2,yshift=-6pt] (c1) {\textbf{rank $A<n$} \\ \textbf{Infinitely many Solutions \\ $n-r$ arbitrary parameters in solution}}};
    \end{tikzpicture}  
    \end{document}

在此处输入图片描述

答案4

我尝试用简单的代码给出我自己的说明。rank A左侧和右侧的文本水平对齐。

在此处输入图片描述

\documentclass[tikz,border=5mm]{standalone}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{tikzpicture}[>=stealth,thick]
\def\a{3}   
\def\b{1.8} 
\path[nodes={draw,minimum width=4.5cm}]
(0,0) node[fill=yellow!50,minimum height=12mm,align=center] (H) {$\mathbf{Ax=0}$\\[1mm]$\mathbf{A}=m\times n, m\leqslant n, \mathbf{x}\in\mathbb{R}^n$}
++(0,-\b) node[fill=cyan!50,minimum height=8mm] (H1){Always consistent}
+(\a,-1.5*\b) node[fill=cyan!50,minimum height=22mm] (H2r){}
+(-\a,-1.5*\b) node[fill=cyan!50,minimum height=22mm] (H2l){}
;
\path 
(H2r.north) node[below=1mm,align=left]{
    Infinitely many Solutions\\[2mm] 
    $r=\text{rank}A<n$\\
    $n-r$ arbitrary\\ 
    parameters in solutions}
(H2l.north) node[below=1mm,align=left]{
    Unique Solution\\[2mm] 
    $r=\text{rank}A=n$
}
;

\draw[->] (H)--(H1); 
\draw[->] (H1)--++(0,-1)-|(H2r);
\draw[->] (H1)--++(0,-1)-|(H2l);
\end{tikzpicture}
\end{document}

相关内容