警告 Tikzfillbetween 和改变模式

警告 Tikzfillbetween 和改变模式

我正在尝试使用 \tikzfillbetween 来填充两个自由曲线之间的图案,这是我目前的代码:

 \documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.13}
\begin{document}

\begin{center}
\begin{tikzpicture}
\coordinate (y) at (0,4);
\coordinate (x) at (7,0);
\draw[->] (0,0)--(x) node[below]{$t$};
\draw[->] (0,0)--(y) node[left]{\scriptsize $Y,C,A$};
\draw[name path=Consume] (0,2) node[left]{\scriptsize $\overline{C}$}--(6,2);
\draw[dashed] (6,2)--(6,0) node[below]{\scriptsize $N$};
\draw[blue, name path=Income] (0,0) to [out=0,in=130] (4,3)--(4,0)--(6,0);
\draw (3.8,3.5) node[left]{\scriptsize $Y_t$};
\tikzfillbetween[of=Consume and Income]{pattern=dots};
\end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述

我需要更改每个不同区域的颜色和图案并删除我收到的警告:

'fill between':无法激活图形层 'pre main'。填充路径将位于其他路径之上。请确保 'premain' 位于图层列表中的某个位置(或设置 '/tikz/fill between/on layer=')。

我尝试在 tikz 手册中搜索它,但找不到 tikzfillbetween 命令。有人能帮我解决这个问题吗,或者告诉我在哪里可以找到这个命令的说明?

谢谢!

编辑:此警告已通过以下方式修复:

在序言中:

\pgfdeclarelayer{ft}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main,ft}

在 Tikz 上

\tikzfillbetween[of=Consume and Income, on layer=ft]

再次感谢 Paul 和 Ignasi

答案1

像这样?

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.13}
\begin{document}

\begin{center}
\begin{tikzpicture}
\coordinate (y) at (0,4);
\coordinate (x) at (7,0);
\draw[->] (0,0)--(x) node[below]{$t$};
\draw[->] (0,0)--(y) node[left]{\scriptsize $Y,C,A$};
\draw[name path=Consume] (0,2) node[left]{\scriptsize $\overline{C}$}--(6,2);
\draw[dashed] (6,2)--(6,0) node[below]{\scriptsize $N$};
\draw[blue, name path=Income] (0,0) to [out=0,in=130] (4,3)--(4,0)--(6,0);
\draw (3.8,3.5) node[left]{\scriptsize $Y_t$};
\tikzfillbetween[of=Consume and Income,
    split,
    every even segment/.style={pattern color=orange}]{pattern=dots, pattern color=green};
\end{tikzpicture}
\end{center}

\end{document}

或这个?

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.13}
\begin{document}

\begin{center}
\begin{tikzpicture}
\coordinate (y) at (0,4);
\coordinate (x) at (7,0);
\draw[->] (0,0)--(x) node[below]{$t$};
\draw[->] (0,0)--(y) node[left]{\scriptsize $Y,C,A$};
\draw[name path=Consume] (0,2) node[left]{\scriptsize $\overline{C}$}--(6,2);
\draw[dashed] (6,2)--(6,0) node[below]{\scriptsize $N$};
\draw[blue, name path=Income] (0,0) to [out=0,in=130] (4,3)--(4,0)--(6,0);
\draw (3.8,3.5) node[left]{\scriptsize $Y_t$};
\tikzfillbetween[of=Consume and Income,
    split,
    every segment no 0/.style={pattern color=orange},
    every segment no 1/.style={pattern color=green},
    every segment no 2/.style={pattern color=blue},
    ]{pattern=dots};
\end{tikzpicture}
\end{center}

\end{document}

相关内容