2

I want the text Yes on the arrow to be closer to the arrow. Is there a nice way to auto-adjust the text to be closer to the arrow?

Thanks in advance!

\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}
2

enter image description here

Code commented with %<--

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.