tikz add tag
Anonymous 1123
Based on the answer [here](https://topanswers.xyz/tex?q=1333), I want to represent intersection ot two sets `(-2,2)` and `(-3,1)`. I tried
```
\documentclass[12pt]{standalone}
\usepackage{tikz}

\usepackage{amsmath}
\usetikzlibrary{patterns.meta}
\tikzset{pics/interval/.style={code={%
\def\pv##1{\pgfkeysvalueof{/tikz/interval/##1}}%
\tikzset{interval/.cd,#1}%
\iftikzintervalscaled
\pgfmathsetmacro{\myintervalscale}{\pv{width}/(\pv{xmax}-\pv{xmin})/1cm}%
\else
\pgfmathsetmacro{\myintervalscale}{1}%
\fi
\pgfmathsetmacro{\xmid}{\pv{xmax}/2+\pv{xmin}/2}%
\begin{scope}[xscale=\myintervalscale,shift={(-\xmid,0)}]
 \draw[interval/axis] (\pv{xmin},0) -- (\pv{xmax},0);
 \pgfmathtruncatemacro{\itest}{(\pv{xmin}<\pv{imin})}%
 \ifnum\itest=1
  \path[interval/excluded]
   (\pv{xmin},-\pv{h}/2) rectangle (\pv{imin},\pv{h}/2);
  \path  ([xshift=0.2ex/\myintervalscale]\pv{imin},0) node {$\pv{left}$}
  	node[interval/both labels,interval/left label]{$\pv{l}$};
 \fi
 \pgfmathtruncatemacro{\itest}{(\pv{xmax}>\pv{imax})}%
 \ifnum\itest=1
  \path[interval/excluded]
   (\pv{imax},-\pv{h}/2) rectangle ([xshift=-1em/\myintervalscale]\pv{xmax},\pv{h}/2);
  \path  ([xshift=-0.2ex/\myintervalscale]\pv{imax},0) node {$\pv{right}$}
  	node[interval/both labels,interval/right label]{$\pv{r}$};
 \fi
\end{scope}
}},
interval/.cd,axis domain/.code args={#1:#2}{%
\tikzset{interval/.cd,xmin=#1,xmax=#2}%
},interval domain/.code args={#1:#2}{%
\tikzset{interval/.cd,imin=#1,imax=#2}%
},xmin/.initial=-5,xmax/.initial=5,
imin/.initial=0,imax/.initial=1,
left/.initial={(},right/.initial={)},
scaled/.is if=tikzintervalscaled,scaled/.default=true,
width/.initial=8cm,h/.initial=9pt,
axis/.style={thick,-stealth},
excluded/.style={pattern={Lines[angle=45,distance={2pt}]}},
both labels/.style={below,text=blue,text height=1.2em},
left label/.style={},right label/.style={},
l/.initial={\pv{imin}},r/.initial={\pv{imax}}
}
\newif\iftikzintervalscaled
\tikzintervalscaledtrue
\begin{document}
\begin{tikzpicture}
\path (0,0) pic{interval={axis domain=-5:5,interval domain=-2:2}}
(0,0) pic{interval={axis domain=-5:5,interval domain=-3:1}}
;
\end{tikzpicture}
\end{document}
```
I got  
![ScreenHunter 845.png](/image?hash=0eb840cd888c16e0e46909148b9fc0b325fcb9fc20360b6780a1aeb1a88e5aad)

I want to style of patterns in each interval is different. The first pattern from right to left, and the second is from left to right. How can I do that.
Top Answer
marmot
You can adjust the `excluded` style in the second interval.

```
\documentclass[12pt]{standalone}
\usepackage{tikz}

\usepackage{amsmath}
\usetikzlibrary{patterns.meta}
\tikzset{pics/interval/.style={code={%
\def\pv##1{\pgfkeysvalueof{/tikz/interval/##1}}%
\tikzset{interval/.cd,#1}%
\iftikzintervalscaled
\pgfmathsetmacro{\myintervalscale}{\pv{width}/(\pv{xmax}-\pv{xmin})/1cm}%
\else
\pgfmathsetmacro{\myintervalscale}{1}%
\fi
\pgfmathsetmacro{\xmid}{\pv{xmax}/2+\pv{xmin}/2}%
\begin{scope}[xscale=\myintervalscale,shift={(-\xmid,0)}]
 \draw[interval/axis] (\pv{xmin},0) -- (\pv{xmax},0);
 \pgfmathtruncatemacro{\itest}{(\pv{xmin}<\pv{imin})}%
 \ifnum\itest=1
  \path[interval/excluded]
   (\pv{xmin},-\pv{h}/2) rectangle (\pv{imin},\pv{h}/2);
  \path  ([xshift=0.2ex/\myintervalscale]\pv{imin},0) node {$\pv{left}$}
  	node[interval/both labels,interval/left label]{$\pv{l}$};
 \fi
 \pgfmathtruncatemacro{\itest}{(\pv{xmax}>\pv{imax})}%
 \ifnum\itest=1
  \path[interval/excluded]
   (\pv{imax},-\pv{h}/2) rectangle ([xshift=-1em/\myintervalscale]\pv{xmax},\pv{h}/2);
  \path  ([xshift=-0.2ex/\myintervalscale]\pv{imax},0) node {$\pv{right}$}
  	node[interval/both labels,interval/right label]{$\pv{r}$};
 \fi
\end{scope}
}},
interval/.cd,axis domain/.code args={#1:#2}{%
\tikzset{interval/.cd,xmin=#1,xmax=#2}%
},interval domain/.code args={#1:#2}{%
\tikzset{interval/.cd,imin=#1,imax=#2}%
},xmin/.initial=-5,xmax/.initial=5,
imin/.initial=0,imax/.initial=1,
left/.initial={(},right/.initial={)},
scaled/.is if=tikzintervalscaled,scaled/.default=true,
width/.initial=8cm,h/.initial=9pt,
axis/.style={thick,-stealth},
excluded/.style={pattern={Lines[angle=45,distance={2pt}]}},
both labels/.style={below,text=blue,text height=1.2em},
left label/.style={},right label/.style={},
l/.initial={\pv{imin}},r/.initial={\pv{imax}}
}
\newif\iftikzintervalscaled
\tikzintervalscaledtrue
\begin{document}
\begin{tikzpicture}
\path (0,0) pic{interval={axis domain=-5:5,interval domain=-2:2}}
  pic{interval={excluded/.style={pattern={Lines[angle=-45,distance={2pt}]}},
  	axis domain=-5:5,interval domain=-3:1}};
\end{tikzpicture}
\end{document}
```

![Screen Shot 2020-09-21 at 9.47.50 PM.png](/image?hash=2d034f0cd3ce20f986e02aa6dba31aa974598410f4419a03c79da550c7cdca2c)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.