我打算在 Beamer 演示文稿中绘制以下图像。你能帮我画一下吗?
我打算使用以下代码,但它给出了有关包的错误。当然,代码并不完整,因为我不知道如何在代码中识别行和行下的区域。
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw[->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
\draw[->,ultra thick] (0,-5)--(0,5) node[above]{$y$};
\end{tikzpicture}
\end{document}
答案1
也许是这样的?我不确定灰色区域应该如何绘制。
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\fill[black!10] (-4,4.5) to[out=0,in=180] (-3,5) -- (5,-3) to[out=180,in=-45] (1,-2) -- (-4,3) -- cycle;
\draw[ultra thick] (-3,5) -- (5,-3) node[above right, midway]{$x_1 + x_2 = y$};
\draw[help lines, color=gray!30, dashed] (-3.9,-3.9) grid (4.9,4.9);
\draw[->, ultra thick] (-4,0) -- (5,0) node[right]{$x_1$};
\draw[->, ultra thick] (0,-4) -- (0,5) node[above]{$x_2$};
\end{tikzpicture}
\end{document}
或者更像原版:
\documentclass[tikz,border=2mm]{standalone}
\usepackage{mathptmx}
\begin{document}
\begin{tikzpicture}
\fill[black!20] (-4,4.5) to[out=0,in=180] (-3,5) -- (5,-3) to[out=180,in=-45] (.5,-1.5) -- (-4,3) -- cycle;
\draw[ultra thick] (-3,5) -- (5,-3) node[above right, midway]{$x_1 + x_2 = y$};
\draw[thick] (-4,0) -- (5,0) node[right]{$x_1$};
\draw[thick] (0,-4) -- (0,5) node[above]{$x_2$};
\end{tikzpicture}
\end{document}
如果你想用图案填充该区域,我推荐patterns
Ti 库钾Z 需要在文档的前言部分加载(在加载包之后tikz
)。请参阅第 62 章钛钾Z/PGF 文档关于不同的选择。
\documentclass[tikz,border=2mm]{standalone}
\usepackage{mathptmx}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\fill[pattern=north east lines] (-4,4.5) to[out=0,in=180] (-3,5) -- (5,-3) to[out=180,in=-45] (.5,-1.5) -- (-4,3) -- cycle;
\draw[ultra thick] (-3,5) -- (5,-3) node[above right, midway]{$x_1 + x_2 = y$};
\draw[thick] (-4,0) -- (5,0) node[right]{$x_1$};
\draw[thick] (0,-4) -- (0,5) node[above]{$x_2$};
\end{tikzpicture}
\end{document}