4

The following figure is a modification of an answer to Sketching free-hand, importing into TikZ.

The labels $K$ and $U_y$ in the picture designate respectively: the blue-filled region that has a thick solid boundary; and the upper-right-most region, with a dashed boundary, that is partly orange-filled but overlaps region K. Each of these labels is obscured by portions of the boundaries: label $K$ by the dashed lower part of the boundary of $U_y$; and label $U_y$ by the solid boundary of region K.

Question: How can I break those two boundaries so as to allow the labels to be more readily seen?

More specifically, is there some nice way to avoid lots of trial-and-error in locating suitable points along the boundaries at which to stop and restart the bounding curves?

(Note: The final picture will use shades of gray instead of colors red, blue, and orange, as specified by the now commented-out code block with the 3 \definecolor commands. I'm leaving the colors as shown so as to indicate more clearly which region is which.)

\documentclass[tikz,border=0pt]{standalone}    
% Based upon answer by @marmot 2018/06/10
% https://tex.stackexchange.com/questions/435746/sketching-free-hand-importing-into-tikz

\usetikzlibrary{calc,intersections,arrows.meta,backgrounds}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

%\definecolor{red}{gray}{0.15} % medium gray for region V
%\definecolor{blue}{gray}{0.2} % dark gray for region K
%\definecolor{orange}{gray}{0.6}% light shading for left & right sides    

\begin{document}

\begin{tikzpicture}[long dash/.style={dash pattern=on 4pt off 2pt},
dot/.style = {circle, fill, minimum size=#1,
              inner sep=0pt, outer sep=0pt},
dot/.default = 3pt,  % size of the circle diameter 
x=0.44cm,y=0.44cm % scale units for overall correct size
] 

% Left-hand regions
\draw[thick,long dash,name path=left,fill=orange!30] plot[smooth cycle] coordinates 
    {(0.3,-2) (-1,-3) (-8,-1.2) (-8.8,-0.2) (-7,0.6) (-1,-0.6)};
\draw[thick,long dash,name path=left bottom] plot[smooth cycle] coordinates 
    {(-8,-2.8) (-9,-2.5) (-8.5,-1) (-7,0) (-6,1.7) (-5,1.7) (-4,-0) (-5.5,-2)};
\draw[thick,long dash,name path=left top] plot[smooth cycle] coordinates 
    {(-7.2,-1) (-7.8,1) (-6.7,2) (-5.5,1) (-5,0) (-5.4,-1) (-6,-1.2)};
\path [%draw,blue,ultra thick,
    name path=left arc,
    intersection segments={
        of=left top and left,
        sequence={A1--B1}
    }];
\path [%draw,red,ultra thick,
    fill=red!30,
    name path=left blob,
    intersection segments={
        of=left bottom and left arc,
        sequence={A1--B0}
    }];
% Right-hand regions
\path[fill=orange!30] plot[smooth cycle] coordinates % region U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\path[fill=blue!30] plot[smooth cycle] coordinates % region K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
(6,-2.3) (4,-2.3) (2,-2)};
\draw[thick,long dash,name path=right top] plot[smooth cycle] coordinates % boundary of U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\draw[thick,name path=right] plot[smooth cycle] coordinates % boundary of K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
    (6,-2.3) (4,-2.3) (2,-2)};
% boundary of unnamed region to lower-left of point y:
\draw[thick,long dash,name path=middle] plot[smooth cycle] coordinates 
    {(0,-3.4) (-1,-2) (-1,-0.5) (-1.5,0.4) (-1,1.6) (0,1.9) (2.1,1) (3,-1) (2.5,-3) (1,-3.7)};
% boundary of unnamed region to lower-rightof point y:
\draw[thick,long dash,name path=right bottom] plot[smooth cycle] coordinates 
    {(1,-3) (0.6,-2) (1.2,0) (3,0.8) (6,0.8) (8.5,1) (10,0) (9,-3) (7,-3.7) (5,-3.6) (2,-3.6)};
\path[name path=circle] (5.2,1.5) arc(-30:190:4mm);
\path [%draw,red,ultra thick,
    name path=aux1,
    intersection segments={
        of=circle and right,
        sequence={B1}
    }];
\path [draw,ultra thick,
    name path=aux2,
    intersection segments={
        of=circle and aux1,
        sequence={B0}
    }];

% Distinguished points & their labels
\node[dot] at (-6.5,-0.425) {};
\node at (-6.95,-0.675) {$x$};
\node[dot] at (3.3,1.5) {};
\node at (2.85,1.25) {$y$}; 

% Region labels
\node at (-5.625,-0.025) {$V$};
\node at (-2.5,-1.5){$V_y$};  
\node[] at (3.7,0){$K$}; 
\node[] at (4.8,1.6) {$U_y$};

\end{tikzpicture}    
\end{document}

Region - need to break two boundaries to let labels be better seen.

  • Well, in the linked answer there is a way: redraw the relevant pieces of the paths with the color of the fill. Another way is to use dash pattern to leave a gap. – marmot Aug 16 '18 at 20:56
  • I think the easiest approach is simply to position the labels so that they don't intersect the paths. That avoids the ambiguity inherent otherwise — is K the label of the region, or the label of the path? – Derek Aug 16 '18 at 21:03
  • 1
    Also, to actually provide assistance rather than just critique, you could change \node[] at (3.7,0){$K$}; to \node[] at (3.7,0)[fill=blue!30]{$K$}; for example. Doing the same for U_y is a little harder. – Derek Aug 16 '18 at 21:05
  • Indeed, I could move the label $K$ off that solid boundary without ambiguity as to the meaning. However, moving label $U_y$ off the dashed boundary will create ambiguity, since it refers to a region larger than the right-hand (now) orange-shaded region and is supposed to indicate that the labeled region includes the part of that orange region that "dips below" the blue-shaded region. – murray Aug 16 '18 at 21:27
6

UPDATE: Something that works for all paths, regardless of whether or not they are dashed: use the reverse clip method. Draw the text node first, and then reverse clip a small region around it and then draw all the contours that you want to have a gap afterwards.

\documentclass[tikz,border=0pt]{standalone}    
% Based upon answer by @marmot 2018/06/10
% https://tex.stackexchange.com/questions/435746/sketching-free-hand-importing-into-tikz

\usetikzlibrary{calc,intersections,arrows.meta,backgrounds,decorations.markings}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
% from https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current page.north east) --
  (current page.south east) --
  (current page.south west) --
  (current page.north west) --
  (current page.north east)}
}}


%\definecolor{red}{gray}{0.15} % medium gray for region V
%\definecolor{blue}{gray}{0.2} % dark gray for region K
%\definecolor{orange}{gray}{0.6}% light shading for left & right sides    

\begin{document}

\begin{tikzpicture}[long dash/.style={dash pattern=on 4pt off 2pt},
dot/.style = {circle, fill, minimum size=#1,
              inner sep=0pt, outer sep=0pt},
dot/.default = 3pt,  % size of the circle diameter 
x=0.44cm,y=0.44cm % scale units for overall correct size
] 

% Left-hand regions
\draw[thick,long dash,name path=left,fill=orange!30] plot[smooth cycle] coordinates 
    {(0.3,-2) (-1,-3) (-8,-1.2) (-8.8,-0.2) (-7,0.6) (-1,-0.6)};
\draw[thick,long dash,name path=left bottom] plot[smooth cycle] coordinates 
    {(-8,-2.8) (-9,-2.5) (-8.5,-1) (-7,0) (-6,1.7) (-5,1.7) (-4,-0) (-5.5,-2)};
\draw[thick,long dash,name path=left top] plot[smooth cycle] coordinates 
    {(-7.2,-1) (-7.8,1) (-6.7,2) (-5.5,1) (-5,0) (-5.4,-1) (-6,-1.2)};
\path [%draw,blue,ultra thick,
    name path=left arc,
    intersection segments={
        of=left top and left,
        sequence={A1--B1}
    }];
\path [%draw,red,ultra thick,
    fill=red!30,
    name path=left blob,
    intersection segments={
        of=left bottom and left arc,
        sequence={A1--B0}
    }];
% Right-hand regions
\path[fill=orange!30] plot[smooth cycle] coordinates % region U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\path[fill=blue!30] plot[smooth cycle] coordinates % region K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
(6,-2.3) (4,-2.3) (2,-2)};
\begin{scope}
\node[] at (3.7,0)[fill=blue!30]{$K$};
\clip[overlay] (3.7,0) circle (8pt) [reverseclip];
\draw[thick,long dash,name path=right top] plot[smooth cycle] coordinates % boundary of U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
% \end{scope}
% \begin{scope} 
\node at (4.8,1.6) {$U_y$};
\clip[overlay] (4.8,1.6) circle (10pt) [reverseclip];
\draw[thick,name path=right] plot[smooth cycle] coordinates % boundary of K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
    (6,-2.3) (4,-2.3) (2,-2)};
\end{scope} 
% boundary of unnamed region to lower-left of point y:
\draw[thick,long dash,name path=middle] plot[smooth cycle] coordinates 
    {(0,-3.4) (-1,-2) (-1,-0.5) (-1.5,0.4) (-1,1.6) (0,1.9) (2.1,1) (3,-1) (2.5,-3) (1,-3.7)};
% boundary of unnamed region to lower-rightof point y:
\draw[thick,long dash,name path=right bottom] plot[smooth cycle] coordinates 
    {(1,-3) (0.6,-2) (1.2,0) (3,0.8) (6,0.8) (8.5,1) (10,0) (9,-3) (7,-3.7) (5,-3.6) (2,-3.6)};
\path[name path=circle] (5.2,1.5) arc(-30:190:4mm);
\path [%draw,red,ultra thick,
    name path=aux1,
    intersection segments={
        of=circle and right,
        sequence={B1}
    }];
\path [draw,ultra thick,
    name path=aux2,
    intersection segments={
        of=circle and aux1,
        sequence={B0}
    }];

% Distinguished points & their labels
\node[dot] at (-6.5,-0.425) {};
\node at (-6.95,-0.675) {$x$};
\node[dot] at (3.3,1.5) {};
\node at (2.85,1.25) {$y$}; 

% Region labels
\node at (-5.625,-0.025) {$V$};
\node at (-2.5,-1.5){$V_y$};  
% Derek's comment

%

\end{tikzpicture}    
\end{document}

enter image description here

OLD ANSWER: Here is a simpleminded method that works for the solid boundary. Tune the lengths of a dash pattern such that there is a gap at the right place. Of course, you can make that more elegant by placing the text with decorations.markings such that it is right in the middle of the gap. Yet for the dashed lines I recommend the method of my previous answer. (If you don't like that method, there is no need to load pgfplots nor its library fillbetween.) EDIT: I was wrong, you do need the fillbetween stuff for the region containing x. I also implemented Derek's nice comment but will be happy to remove it.

\documentclass[tikz,border=0pt]{standalone}    
% Based upon answer by @marmot 2018/06/10
% https://tex.stackexchange.com/questions/435746/sketching-free-hand-importing-into-tikz

\usetikzlibrary{calc,intersections,arrows.meta,backgrounds,decorations.markings}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

%\definecolor{red}{gray}{0.15} % medium gray for region V
%\definecolor{blue}{gray}{0.2} % dark gray for region K
%\definecolor{orange}{gray}{0.6}% light shading for left & right sides    

\begin{document}

\begin{tikzpicture}[long dash/.style={dash pattern=on 4pt off 2pt},
dot/.style = {circle, fill, minimum size=#1,
              inner sep=0pt, outer sep=0pt},
dot/.default = 3pt,  % size of the circle diameter 
x=0.44cm,y=0.44cm % scale units for overall correct size
] 

% Left-hand regions
\draw[thick,long dash,name path=left,fill=orange!30] plot[smooth cycle] coordinates 
    {(0.3,-2) (-1,-3) (-8,-1.2) (-8.8,-0.2) (-7,0.6) (-1,-0.6)};
\draw[thick,long dash,name path=left bottom] plot[smooth cycle] coordinates 
    {(-8,-2.8) (-9,-2.5) (-8.5,-1) (-7,0) (-6,1.7) (-5,1.7) (-4,-0) (-5.5,-2)};
\draw[thick,long dash,name path=left top] plot[smooth cycle] coordinates 
    {(-7.2,-1) (-7.8,1) (-6.7,2) (-5.5,1) (-5,0) (-5.4,-1) (-6,-1.2)};
\path [%draw,blue,ultra thick,
    name path=left arc,
    intersection segments={
        of=left top and left,
        sequence={A1--B1}
    }];
\path [%draw,red,ultra thick,
    fill=red!30,
    name path=left blob,
    intersection segments={
        of=left bottom and left arc,
        sequence={A1--B0}
    }];
% Right-hand regions
\path[fill=orange!30] plot[smooth cycle] coordinates % region U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\path[fill=blue!30] plot[smooth cycle] coordinates % region K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
(6,-2.3) (4,-2.3) (2,-2)};
\draw[thick,long dash,name path=right top] plot[smooth cycle] coordinates % boundary of U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\draw[thick,name path=right,dash pattern=on 118pt off 16pt on 300pt,
postaction={decorate,decoration={markings,mark=at position 126pt with
{\node{$U_y$};}}}] plot[smooth cycle] coordinates % boundary of K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
    (6,-2.3) (4,-2.3) (2,-2)};
% boundary of unnamed region to lower-left of point y:
\draw[thick,long dash,name path=middle] plot[smooth cycle] coordinates 
    {(0,-3.4) (-1,-2) (-1,-0.5) (-1.5,0.4) (-1,1.6) (0,1.9) (2.1,1) (3,-1) (2.5,-3) (1,-3.7)};
% boundary of unnamed region to lower-rightof point y:
\draw[thick,long dash,name path=right bottom] plot[smooth cycle] coordinates 
    {(1,-3) (0.6,-2) (1.2,0) (3,0.8) (6,0.8) (8.5,1) (10,0) (9,-3) (7,-3.7) (5,-3.6) (2,-3.6)};
\path[name path=circle] (5.2,1.5) arc(-30:190:4mm);
\path [%draw,red,ultra thick,
    name path=aux1,
    intersection segments={
        of=circle and right,
        sequence={B1}
    }];
\path [draw,ultra thick,
    name path=aux2,
    intersection segments={
        of=circle and aux1,
        sequence={B0}
    }];

% Distinguished points & their labels
\node[dot] at (-6.5,-0.425) {};
\node at (-6.95,-0.675) {$x$};
\node[dot] at (3.3,1.5) {};
\node at (2.85,1.25) {$y$}; 

% Region labels
\node at (-5.625,-0.025) {$V$};
\node at (-2.5,-1.5){$V_y$};  
% Derek's comment
\node[] at (3.7,0)[fill=blue!30]{$K$};
%\node[] at (4.8,1.6) {$U_y$};

\end{tikzpicture}    
\end{document}

enter image description here

  • Perfect! Thank you. Locating how to do such things in the TikZ manual is difficulty-to-impossible (at least for me at this beginning stage of using the package)! – murray Aug 16 '18 at 21:53
  • @marmot Sorry, off-topic: How did you get the reference to my comment in your answer? I didn't know that was possible. Thanks for the nice mention, BTW. – Derek Aug 16 '18 at 23:22
  • @Derek You make a right-click on the date next to the comment and then select copy link. Similarly, you can share answers by right-clicking on share below an answer and copying the link. (It took me also some time to figure that out.) (And if you want I can remove that part and you can write your own answer.) – marmot Aug 16 '18 at 23:25
  • 1
    @marmot Great, thanks! Please don't worry about changing your answer. – Derek Aug 16 '18 at 23:38
  • @marmot: Even nicer. – murray Aug 17 '18 at 21:34

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.