How to partially make a segment of a path dashed?

Just divide the path in three if you want the second part dashed.

If you write NodeName.degreee (for example X.130) you can position the end or the beginning of the path exactly where you need. Imagine the node is a circle angle with the east anchor = 0 degrees, so the south anchor is -90, the north = 90, the east = 180, etc.

\documentclass[border=1in]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
    block/.style={
        rectangle, draw, fill=blue!20, 
        text width=5em, text centered, rounded corners, minimum height=4em
        }
    }

\begin{document}
    \begin{tikzpicture}
    \node [block] (X) {X};
    \node [block] [below left=of X] (A) {A};
    \node [block] [above left=of X] (a) {a};
    \node [block] [below right=of X] (B) {B};
    \node [block] [above right=of X] (b) {b};

    \draw (A) to[bend right] (X.-130) node[below left=4pt and 5pt] {$q(x)$};
    \draw[dashed] (X.-130) to[bend right, looseness=.2] (X.130); 
    \draw[->] (X.130) to[bend right] (a);

    \draw (B) to[bend left] (X.-50) node[below right=4pt and 5pt] {$f(x)$};
    \draw[dashed] (X.-50) to[bend left, looseness=.2] (X.50);
    \draw[->] (X.50) to[bend left] (b);

    \end{tikzpicture}
\end{document}

enter image description here

Edit: gorgeous marmot's answer could be simplified without using reverse clipping and putting the straight line behind the X node, like in marya's answer but using on background layer from backgrounds library to not draw it twice.

\documentclass[border=1in]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,backgrounds}
\tikzset{
    block/.style={
        rectangle, 
        text width=5em,  text centered, rounded corners, minimum height=4em, draw, fill=blue!20
        },
    }

\begin{document}
\begin{tikzpicture}
    \node[block] (X) {X};
    \node [block] [below left=of X] (A) {A};
    \node [block] [above left=of X] (a) {a};
    \node [block] [below right=of X] (B) {B};
    \node [block] [above right=of X] (b) {b};

    \begin{scope}[on background layer]
    \path[->] (A) edge[bend right=90] node[near start, above left] {$q(x)$} (a);
    \path[->] (B) edge[bend left=90]  node[near start, above right] {$f(x)$} (b);
    \end{scope}

    \begin{scope}[dashed]
    \clip[rounded corners] (X.north west) rectangle (X.south east);
    \path[->] (A) edge[bend right=90] (a);
    \path[->] (B) edge[bend left=90]  (b);
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here


Well, the easiest solution I came up is this one

\documentclass[border=1in]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]

\begin{document}
    \begin{tikzpicture}
    \node [block] (X) {X};
    \node [block] [below left=of X] (A) {A};
    \node [block] [above left=of X] (a) {a};
    \node [block] [below right=of X] (B) {B};
    \node [block] [above right=of X] (b) {b};

    \path[->] (A) edge[bend right=90] node [left,pos=0.3] {$q(r)$} (a);
    \path[->] (B) edge[bend left=90] node [right,pos=0.3] {$f(r)$} (b);
\node [block] (X) {X};
\path[->,dashed] (A) edge[bend right=90] node [left,pos=0.3] { } (a);
    \path[->,dashed] (B) edge[bend left=90] node [right,pos=0.3] { } (b);
    \end{tikzpicture}
\end{document} 

enter image description here


Here is a proposal using reverseclip and use path to draw the dashed path inside and the solid one outside. Please note that \tikzstyle is slightly deprecated.

\documentclass[border=1in]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\tikzset{remember path/.style={save path=\tmprotect}}
% https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current bounding box.north
        east) rectangle (current bounding box.south west)}}}

\tikzset{block/.style={rectangle, draw, fill=blue!20, 
text width=5em, text centered, rounded corners, minimum height=4em}}

\begin{document}
    \begin{tikzpicture}
    \node [block,save path=\pathX] (X) {X};
    \node [block] [below left=of X] (A) {A};
    \node [block] [above left=of X] (a) {a};
    \node [block] [below right=of X] (B) {B};
    \node [block] [above right=of X] (b) {b};

    \begin{scope}
    \clip[use path=\pathX,reverseclip];
    \path[->] (A) edge[bend right=90] (a);
    \path[->] (B) edge[bend left=90]  (b);
    \end{scope}
    \begin{scope}[dashed]
    \clip[use path=\pathX];
    \path[->] (A) edge[bend right=90] (a);
    \path[->] (B) edge[bend left=90]  (b);
    \end{scope}

    \end{tikzpicture}
\end{document}

enter image description here

Tags:

Tikz Pgf