3

I realize that I have to plot different figure then this one. Interestingly, @marmot has already provided a wonderful and very beautiful solution. I will use their code for MWE alogwith mine(small part). But I couldn't achieve the new figure as well. enter image description here My MWE

\documentclass[margin=3.14mm]{standalone}
\usepackage{tikz}
\usepackage{contour}
\contourlength{1pt}
\tikzset{mynode/.style args={#1 | #2}{midway,%
        node contents={\contour{white}{\textcolor{#1}{#2}}},%
        font=\small,inner sep=0pt}}
\usetikzlibrary{calc,patterns}
\begin{document}
    \begin{tikzpicture}
    \draw[pattern=north west lines,pattern color=blue,draw=blue] (0,0) rectangle (3,1)
    node[mynode=blue | blue];
    \draw[pattern=vertical lines] (2,0) rectangle (5,1) 
    node[mynode=black | black];
    \draw[pattern=horizontal lines,pattern color=yellow,draw=yellow] 
    (0:2cm) -- (0:3cm)
    arc (0:105:3cm) -- (105:2cm) node[mynode=yellow | yello]
    arc (105:0:2cm) -- cycle;
    \draw[pattern=north east lines,pattern color=red,draw=red] (-1,0) -- (0,0)
    arc (180:120:2cm) -- (120:1cm) node[mynode=red | red]
    arc (120:180:1cm) -- cycle;
    \end{tikzpicture}
\end{document}
5

I had to slightly adjust the style made by @marmot in the question you referenced to, so that you can place the nodes wherever you want. I only removed the midway option.

Using the ++(<x>,<y>) notation you can specify a coordinate relative to the last coordinate Tikz processed. This also works with the ++(<angle>:<radius>) polar coordinates.

\documentclass[margin=3.14mm]{standalone}
\usepackage{tikz}
\usepackage{contour}
\contourlength{1pt}
\tikzset{mynode/.style args={#1 | #2}{%midway,%
        node contents={\contour{white}{\textcolor{#1}{#2}}},%
        font=\small,inner sep=0pt}}
\usetikzlibrary{calc,patterns}
\begin{document}
    \begin{tikzpicture}
    \draw[pattern=north west lines,pattern color=blue] 
        (-1,0) rectangle (3,1) node[mynode=blue | Blue,midway];
    \draw[pattern=vertical lines] 
        (2,0) rectangle (5,1) node[mynode=black | Black,midway];
    \draw[pattern=horizontal lines,pattern color=yellow] 
        (2,0) -- ++(0,1) arc (0:105:1cm) -- ++(105:1cm) arc (105:0:2cm) -- ++(0,-1) -- cycle;
    \node at (2,2) [mynode=yellow | Hello];
    \draw[pattern=north east lines,pattern color=red] 
        (0,0) -- ++(0,1) arc (180:75:1cm) -- ++(75:1cm) arc (75:180:2cm) -- ++(0,-1) -- cycle;
    \node at (0,2) [mynode=red | Red];
    \end{tikzpicture}
\end{document}

enter image description here

  • 1
    Yes, midway was specific to the previous question, didn't expect to be migrated. ;-) +1 of course ;-) – marmot Jul 17 '18 at 14:15
  • @Max Is there a way to write Red and Yellow in curve manner(just for anesthetic)? Many thanks! – Shamina Jul 17 '18 at 14:29
  • 1
    @Shamina well, I believe it is possible, but it seems to interfere with the contour package. You should ask a separate question and let the TeX magicians work on it :) – Max Jul 17 '18 at 14:41
4

Just for completeness: without redefining the mynode style and yellow on the left and red on the right as in the OP's sketch. The contours are adapted from Max Snippe's great answer (or, more precisely, stolen ;-), and of course with a cheat (which, however, spares you from putting the coordinates of the nodes in the rectangles by hand ;-).

\documentclass[margin=3.14mm]{standalone}
\usepackage{tikz}
\usepackage{contour}
\contourlength{1pt}
\tikzset{mynode/.style args={#1 | #2}{midway,%
        node contents={\contour{white}{\textcolor{#1}{#2}}},%
        font=\small,inner sep=0pt}}
\usetikzlibrary{calc,patterns}
\begin{document}
    \begin{tikzpicture}
    \draw[pattern=north west lines,pattern color=blue,draw=blue] (0,0) rectangle (3,1)
    node[mynode=blue | blue];
    \draw[pattern=vertical lines] (2,0) rectangle (5,1) 
    node[mynode=black | black];
    \draw[pattern=north east lines,pattern color=red] 
        (2,0) -- ++(0,1) arc (0:105:1cm) -- ++(105:1cm) arc (105:0:2cm) -- ++(0,-1) -- cycle;
    \draw[pattern=horizontal lines,pattern color=yellow] 
        (0,0) -- ++(0,1) arc (180:75:1cm) -- ++(75:1cm) arc (75:180:2cm) -- ++(0,-1) -- cycle;
    \path (0,2) -- (0,2) node[mynode=yellow | yello] 
    (2,2) --(2,2) node[mynode=red | Red];
    \end{tikzpicture}
\end{document}

enter image description here

@Shamina: this is really just for fun, please accept Max Snippe's answer.

ADDENDUM: There seem to be some issues with the contour, at least in the conversion to png. One way to fix it is to increase the contour number.

\documentclass[margin=3.14mm]{standalone}
\usepackage{tikz}
\usepackage{contour}
\contourlength{1pt}
\contournumber{64}
\tikzset{mynode/.style args={#1 | #2}{midway,%
        node contents={\contour{white}{\textcolor{#1}{#2}}},%
        font=\small,inner sep=0pt}}
\usetikzlibrary{calc,patterns}
\begin{document}
    \begin{tikzpicture}
    \draw[pattern=north west lines,pattern color=blue,draw=blue] (0,0) rectangle (3,1)
    node[mynode=blue | blue];
    \draw[pattern=vertical lines] (2,0) rectangle (5,1) 
    node[mynode=black | black];
    \draw[pattern=north east lines,pattern color=red] 
        (2,0) -- ++(0,1) arc (0:105:1cm) -- ++(105:1cm) arc (105:0:2cm) -- ++(0,-1) -- cycle;
    \draw[pattern=horizontal lines,pattern color=yellow] 
        (0,0) -- ++(0,1) arc (180:75:1cm) -- ++(75:1cm) arc (75:180:2cm) -- ++(0,-1) -- cycle;
    \path (0,2) -- (0,2) node[mynode=yellow | yellow] 
    (2,2) --(2,2) node[mynode=red | Red];
    \end{tikzpicture}
\end{document}

enter image description here

  • Why does the contour not work on the yello node? (+1 of course for cheating). – Max Jul 17 '18 at 14:46
  • 1
    @MaxSnippe Actually, on my pdf there is a contour. But I agree, for some reason this does not look like that on the converted png. One way to go is to set \contournumber{64} to make really really sure that in the conversion nothing goes wrong. – marmot Jul 17 '18 at 14:52

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.