如何调整 tikzpicture 中箭头上文字的位置?(MWE 可用)

如何调整 tikzpicture 中箭头上文字的位置?(MWE 可用)

我希望箭头上的文字Yes更靠近箭头。有没有一种好的方法可以自动调整文字以更靠近箭头?

提前致谢!

\documentclass{beamer}
\mode<presentation>{\usetheme{Madrid}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{graphicx}
\usepackage{color}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{arrows.meta,backgrounds,fit,matrix}

\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, thick, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{bubble} = [ellipse, minimum width=2cm, minimum height=2em, text centered, text width=2cm, draw, fill=blue!20]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{frame}[t]{Text on Arrows}{}

    \begin{tikzpicture}[node distance=3cm, 
                        auto, 
                        text width=3cm, 
                        scale=0.6, 
                        every node/.style={transform shape,text width=3cm}]
    
    \node (p41) [process] {root};

    \node<.(1)-> (child1) [bubble, below of=p41, xshift=-2cm] {child1};
        \draw<.(1)-> [arrow] (p41.south) -- node[anchor=south] {Yes}(child1.north);
        
    \node<.(1)-> (child2) [bubble, below of=p41, xshift=2cm] {child2};
        \draw<.(1)-> [arrow] (p41.south) -- node {No}(child2.north);

    \end{tikzpicture}
\end{frame}

答案1

在此处输入图片描述

代码注释为%<--

\documentclass{beamer}
\mode<presentation>{\usetheme{Madrid}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{graphicx}
\usepackage{color}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{arrows.meta,backgrounds,fit,matrix}

\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, thick, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{bubble} = [ellipse, minimum width=2cm, minimum height=2em, text centered, text width=2cm, draw, fill=blue!20]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{frame}[t]{Text on Arrows}{}

    \begin{tikzpicture}[node distance=3cm, 
                        auto, 
                        %text width=3cm,%<-- this text enlarges the YES node which is 3 cm wide and thus shifts it to the left
                        scale=0.6, 
                       % every node/.style={transform shape,text width=3cm}% <-- same 
                        ]
    
    \node (p41) [process] {root};

    \node<.(1)-> (child1) [bubble, below of=p41, xshift=-2cm] {child1};
        \draw<.(1)-> [arrow] (p41.south) -- node[swap] {Yes}(child1.north);%<-- swap to change the position of auto 
        
    \node<.(1)-> (child2) [bubble, below of=p41, xshift=2cm] {child2};
        \draw<.(1)-> [arrow] (p41.south) -- node {No}(child2.north);

    \end{tikzpicture}
\end{frame}

\end{document}

相关内容