2

Desired output:

enter image description here

Here is an MWE which achieves exactly that:

\documentclass[11pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,backgrounds,matrix,patterns}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}

\makeatletter
\pgfdeclarepatternformonly[\LineSpace]{diagright}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\LineSpace}{\LineSpace}}{\pgfqpoint{\LineSpace}{\LineSpace}}%
{
    \pgfsetcolor{\tikz@pattern@color}
    \pgfsetlinewidth{0.4pt}
    \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
    \pgfpathlineto{\pgfqpoint{\LineSpace + 0.1pt}{\LineSpace + 0.1pt}}
    \pgfusepath{stroke}
}

\pgfdeclarepatternformonly[\LineSpace]{diagleft}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\LineSpace}{\LineSpace}}{\pgfqpoint{\LineSpace}{\LineSpace}}%
{
    \pgfsetcolor{\tikz@pattern@color}
    \pgfsetlinewidth{1pt}
    \pgfpathmoveto{\pgfqpoint{0pt}{\LineSpace}}
    \pgfpathlineto{\pgfqpoint{\LineSpace + 0.1pt}{-0.1pt}}
    \pgfusepath{stroke}
}
\makeatother

\newdimen\LineSpace
\tikzset{
    line space/.code={\LineSpace=#1},
    line space=8pt
}


\begin{document}

    \begin{tikzpicture}
    \draw[name path = axis] (0,5) node[below left]{1}node[above]{$S_2$} --(0,0) node[below left]{0}--(5,0)node[right]{$S_1$} node[below]{$1$}--(5,5)--(0,5);
    \draw [name path = B1, thick] (0,5)--(1,5)..controls (3,4) and (3.5,2)..(4,0);
    \draw [name path = B2, thick] (0,5)--(0,4)..controls (1,3.5) and (2,1.5)..(3,0)--(4,0);
    \begin{pgfonlayer}{bg}
    \fill [pattern= diagright,
    intersection segments={of=B1 and B2,sequence={L2--R2}}];
    \end{pgfonlayer}
    \end{tikzpicture}


\end{document}

The control of pattern 'density' (note the use of pattern = diagright rather than north east lines) was achieved using @Red's answer here. Specifically, it is controlled via the dimension of \Linespace.

I am currently in the process of making a template for LaTeX newbies to follow (this particular template demonstrates how to shade between lines). However, they are often intimidated by modifications like the one employed here.

Noting that Red's answer was in 2013, is there a new, simpler way to achieve this goal of controlling pattern density? Maybe something like pattern density = X?

Thev
  • 1,568
  • 3
    AFAIK there is no predefined pattern of this type in which you can control the distance between the lines. However, an IMHO simpler and more powerful pattern definition of this type can be found here. –  Oct 16 '18 at 14:47

1 Answers1

3

This isn't quite the answer I was searching for, but it is a simpler (and as @marmot points out - more powerful) way of doing it, as per @Jake's answer here.

My key addition to Jake's answer is that I have defined 4 different styles of line, which are ready to use 'out of the box'.

  1. northeast - Lines sloping from bottom left to top right.
  2. northwest - Lines sloping from bottom right to top left.
  3. vertical - Vertical lines.
  4. horizontal - Horizontal lines.

Why is it more powerful?

  1. The thickness of the lines can be controlled by adding hatch thickness = X.
  2. The distance lines can be controlled by adding hatch distance = X.
  3. You can specify the color as per usual, with pattern color = color, although comments on the original post suggest this does not work if you use it more than once.

MWE demonstrating this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,backgrounds,matrix,patterns}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}

\tikzset{
    hatch distance/.store in=\hatchdistance,
    hatch distance=10pt,
    hatch thickness/.store in=\hatchthickness,
    hatch thickness=0.3pt
}

\makeatletter
\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{northeast}
{\pgfqpoint{0pt}{0pt}}
{\pgfqpoint{\hatchdistance}{\hatchdistance}}
{\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
{
    \pgfsetcolor{\tikz@pattern@color}
    \pgfsetlinewidth{\hatchthickness}
    \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
    \pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
    \pgfusepath{stroke}
}

\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{northwest}
{\pgfqpoint{0pt}{0pt}}
{\pgfqpoint{\hatchdistance}{\hatchdistance}}
{\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
{
    \pgfsetcolor{\tikz@pattern@color}
    \pgfsetlinewidth{\hatchthickness}
    \pgfpathmoveto{\pgfqpoint{\hatchdistance}{0pt}}
    \pgfpathlineto{\pgfqpoint{0pt}{\hatchdistance}}
    \pgfusepath{stroke}
}

\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{horizontal}
{\pgfqpoint{0pt}{0pt}}
{\pgfqpoint{\hatchdistance}{\hatchdistance}}
{\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
{
    \pgfsetcolor{\tikz@pattern@color}
    \pgfsetlinewidth{\hatchthickness}
    \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
    \pgfpathlineto{\pgfqpoint{\hatchdistance}{0pt}}
    \pgfusepath{stroke}
}

\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{vertical}
{\pgfqpoint{0pt}{0pt}}
{\pgfqpoint{\hatchdistance}{\hatchdistance}}
{\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
{
    \pgfsetcolor{\tikz@pattern@color}
    \pgfsetlinewidth{\hatchthickness}
    \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
    \pgfpathlineto{\pgfqpoint{0pt}{\hatchdistance}}
    \pgfusepath{stroke}
}
\makeatother



\begin{document}

    \begin{tikzpicture}
    \draw[name path = axis] (0,5) node[below left]{1}node[above]{$S_2$} --(0,0) node[below left]{0}--(5,0)node[right]{$S_1$} node[below]{$1$}--(5,5)--(0,5);
    \draw [name path = B1, thick] (0,5)--(1,5)..controls (3,4) and (3.5,2)..(4,0);
    \draw [name path = B2, thick] (0,5)--(0,4)..controls (1,3.5) and (2,1.5)..(3,0)--(4,0);
    \begin{pgfonlayer}{bg}
    \fill [pattern=northeast, hatch distance=15pt, hatch thickness = 0.5pt,
    intersection segments={of=B1 and B2,sequence={L2--R2}}];
    \end{pgfonlayer}
    \end{tikzpicture}


\end{document}
Thev
  • 1,568