有没有更简单的方法来控制图案密度?

有没有更简单的方法来控制图案密度?

期望输出:

在此处输入图片描述

下面是一个可以准确实现这一点的 MWE:

\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}

图案“密度”的控制(注意使用pattern = diagright而不是north east lines)是使用@Red 的答案实现的这里。具体来说,它是通过的维度来控制的\Linespace

我目前正在制作一个供 LaTeX 新手使用的模板(这个模板演示了如何在线条之间添加阴影)。然而,他们经常被这里使用的修改吓到。

注意到 Red 的答案是在 2013 年,有没有一种新的、更简单的方法来实现控制图案密度的目标?也许是类似的东西pattern density = X

答案1

这不是我正在寻找的答案,但它是一种更简单(并且正如@marmot 指出的那样 - 更强大)的方法,正如@Jake 的回答这里

我对杰克的回答的主要补充是,我定义了 4 种不同的线条样式,可以“开箱即用”。

  1. northeast- 线条从左下方倾斜到右上方。
  2. northwest- 线条从右下方倾斜到左上方。
  3. vertical- 垂直线。
  4. horizontal- 水平线。

为什么说它的威力更大呢?

  1. 可以通过添加来控制线条的粗细hatch thickness = X
  2. 可以通过添加来控制距离线hatch distance = X
  3. 您可以按照平常的方式使用 来指定颜色,但pattern color = color原始帖子中的评论表明,如果您多次使用它,则此方法不起作用。

MWE 证明了这一点:

\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}

相关内容