Tikz:箭头超出了矩形的限制

Tikz:箭头超出了矩形的限制

我在使用 Tikz 包时遇到了一些问题。我的目的是构建一个图表。但是,有些箭头超出了矩形的限制,这让图像变得非常糟糕(下面用红色突出显示)。

有人知道如何解决这个问题吗?我已经尝试为矩形填充颜色添加一些不透明度,但没有任何效果。

请在下面找到我的代码。

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}

\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{positioning, calc}
\tikzstyle{caixa} = [rectangle, rounded corners, minimum width=3 cm, minimum height=1.8cm, text centered, draw=black, fill=white, thick, text=black, text opacity=1, fill opacity=0]
\tikzstyle{fantasma} = [rectangle, text centered, draw=white, fill=white]
\tikzstyle{seta} = [thick,->,>=stealth]
\tikzstyle{tracejada} = [thick,->,>=stealth, dashed]
\tikzstyle{linha} = [thick,>=stealth]

\begin{document}

    \begin{tikzpicture}[node distance=2.5cm, auto, >=latex', scale=1.2\textwidth]
        \node (egressos) [caixa, anchor=west, text width=3cm] {\textbf{Egressos do ensino médio de 16--22 anos}};
        \node (semchave) [caixa, above of=egressos, text width=3cm, xshift=4cm] {\textbf{Sem chave de identificação}};
        \node (comchave) [caixa, below of=egressos, text width=3cm, xshift=4cm] {\textbf{Com chave de identificação}};
        \node (semenem) [caixa, above of=comchave, text width=3cm, xshift=4cm] {\textbf{Não participantes do Enem}};
        \node (comenem) [caixa, below of=comchave, text width=3cm, xshift=4cm] {\textbf{Participantes do Enem}};
        \node (naoingresso) [caixa, right of=semenem, text width=3cm, xshift=2.5cm] {\textbf{Não ingressantes do ensino superior}};
        \node (ingresso) [caixa, right of=comenem, text width=3cm, xshift=2.5cm] {\textbf{Ingressantes do ensino superior}};
        
        \node (1) [fantasma, below of=egressos, yshift=1.2cm] {N = 1.754.615};
        \node (2) [fantasma, below of=semchave, yshift=1.2cm] {N = 57.386};
        \node (3) [fantasma, below of=comchave, yshift=1.2cm] {N = 1.697.229};
        \node (4) [fantasma, below of=semenem, yshift=1.2cm] {N = 581.299};
        \node (5) [fantasma, below of=comenem, yshift=1.2cm] {N = 1.115.930};
        \node (6) [fantasma, below of=naoingresso, yshift=1.2cm] {N = 776.025};
        \node (7) [fantasma, below of=ingresso, yshift=1.2cm] {N = 921.204};
        
        \node (8) [fantasma, left=0.1cm of semchave, yshift=2mm] {3,3\%};
        \node (9) [fantasma, left=0.1cm of comchave, yshift=-2mm] {96,7\%};
        \node (10) [fantasma, left=0.1cm of semenem, yshift=2mm] {34,2\%};
        \node (11) [fantasma, left=0.1cm of comenem, yshift=-2mm] {65,8\%};
        
        \node [coordinate] (joint1) [right of=egressos, node distance=2.0cm]{};
        \node [coordinate] (joint2) [right of=comchave, node distance=2.0cm, yshift=-0.2mm]{};
        \node [coordinate] (joint3) [right of=semenem, node distance=2.1cm]{};
        \node [coordinate] (joint4) [right of=comenem, node distance=2.4cm, yshift=-0.39mm]{};
        
        \draw[linha] (egressos) -- (joint1);
        \draw[seta] (joint1) |- (semchave);
        \draw[seta] (joint1) |- (comchave);
        \draw[linha] (comchave.east) -- (joint2);
        \draw[seta] (joint2) |- (semenem);
        \draw[seta] (joint2) |- (comenem);
        \draw[linha] (semenem.east) -- (joint3);
        \draw[tracejada] (joint3) |- node[above, very near end] {74,9\%} (naoingresso.155);
        \draw[tracejada] (joint3) |- node[above, very near end] {25,1\%} (ingresso.155);
        \draw[linha] (comenem.east) -- (joint4);
        \draw[seta] (joint4) |- node[below, pos=0.85] {30,6\%} (naoingresso.208);
        \draw[seta] (joint4) |- node[below, pos=0.85] {69,4\%} (ingresso.208);
        
    \end{tikzpicture}

\end{document}

图片如下:

在此处输入图片描述

答案1

使用您的文档示例无法重现显示的图像。显示的图像不是由提供的代码生成的。

无论如何,您的图像代码可以重写为简洁且更短的代码,该代码考虑了定义常见图片元素样式的最新语法,使用positioning库中定义的定位语法:

\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                calc,
                positioning,
                shapes.geometric}
\tikzset{ 
       caixa/.style = {shape=rectangle, rounded corners, draw, thick,  
                       minimum height=15mm, text width=28mm, 
                       align=flush center, font=\bfseries},
 every label/.style = {font=\small},
          el/.style = {font=\small, pos=1, anchor=#1 east}, 
        seta/.style = {thick,-{Stealth[scale=0.8]}},
%\tikzstyle{tracejada} = [thick,->,>=stealth, dashed]
%\tikzstyle{linha} = [thick,>=stealth]
        }
        
\begin{document}
    \begin{tikzpicture}[auto,
node distance = 4mm and 8mm,  
                        ]
\node (egressos)   [caixa,
                    label=below:{$N = 1.754.615$}
                    ]   {Egressos do ensino médio de 16--22 anos};
\node (semchave)   [caixa, 
                    label=below:{$N = 57.386$},
                    above right=of egressos
                    ]   {Sem chave de identificação};
\node (comchave)    [caixa, 
                     label=below:{$N = 1.697.229$},
                     below right=of egressos,
                     ]  {Com chave de identificação};
\node (semenem)     [caixa, 
                     label=below:{$N = 581.299$},
                     above right=of comchave
                     ] {Não participantes do Enem};
\node (comenem)     [caixa, 
                     label=below:{$N = 581.299$},
                     below right=of comchave
                     ]  {Participantes do Enem};
\node (naoingresso) [caixa, 
                     label=below:{$N = 1.115.930$},
                     right=18mm of semenem
                     ]  {Não ingressantes do ensino superior};
\node (ingresso)    [caixa, 
                     label=below:{$N = 776.025$},
                     at={(comenem -| naoingresso)}
                     ]  {Ingressantes do ensino superior};
% conection between nodes
    \begin{scope}[every path/.append style=seta]
\draw   (egressos.east) -- ++ (0.3,0) coordinate (join1)
                        |- (semchave) node[el=south] {\SI{3.3}{\%}}; 
\draw   (join1.east)    |- (comchave) node[el=north] {\SI{96.7}{\%}};

\draw   (comchave.east) -- ++ (0.3,0) coordinate (join2)
                        |- (semenem) node[el=south] {\SI{34.2}{\%}};
\draw   (join2.east)    |- (comenem) node[el=north] {\SI{65.8}{\%}};

\draw   (comenem.east)  -- ++ (0.6,0) coordinate (join3)
                        |- (naoingresso) node[el=north] {\SI{30.6}{\%}};
\draw   (join3.east)    |- (ingresso)    node[el=north] {\SI{69.4}{\%}};
% dashed
    \end{scope}
    \begin{scope}[every path/.append style={seta, dashed},
                  transform canvas={yshift=2ex}]
\draw   (semenem.east)  -- ++ (0.3,0) coordinate (join3)
                        |- (naoingresso) node[el=south] {\SI{74.9}{\%}};
\draw   (join3.east)    |- (ingresso)    node[el=south] {\SI{25.1}{\%}};
    \end{scope}
   \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容