2

I intend to draw the following image in beamer presentation. May you please help me to draw that?

enter image description here

I intend to use the following code but it gives an error about package. Of course, the code is not complete because I do not know how to identify the line and the area under that in the code.

\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}
3
  • 1
    Please show us the code you tried so far ...
    – Mensch
    Commented Nov 1, 2021 at 17:19
  • Please show your code and state errors you got.
    – mmr
    Commented Nov 1, 2021 at 17:32
  • If I had a specific code, I would put on that, but I need any help for writing a proper code
    – user118746
    Commented Nov 1, 2021 at 17:50

1 Answer 1

2

Maybe something like this? I am not sure how the grey area should be drawn.

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

enter image description here

Or even more like the original:

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

enter image description here

If you would like to fill the area with a pattern, I would recommend the patterns library of TikZ that needs to be loaded in the preamble of your document (after having loaded the tikz package). Please consult chapter 62 of the TikZ/PGF documentation regarding the different options.

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

enter image description here

8
  • Thank you very much for your help. Regarding the grey area, it just shows the area under the line, nothing more
    – user118746
    Commented Nov 1, 2021 at 18:49
  • I put the code on the file, now I have the following errors: Latex error: Environment tikspicture undefined. Missing number, treated as zero. Illegal unit of measure (pt inserted). Undefined control sequence. Latex error: \begin{minipage} on input line ended by \end{tikzpicture}
    – user118746
    Commented Nov 1, 2021 at 18:52
  • 1
    You need to load TikZ. Put \usepackage{tikz} in your preamble. Commented Nov 1, 2021 at 19:15
  • And How can I reduce its size?
    – user118746
    Commented Nov 1, 2021 at 19:18
  • If I want to put some pattern instead of gray color under the line, what should I do?
    – user118746
    Commented Nov 1, 2021 at 19:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .