我尝试绘制 $x<y$ 和 $2x<y$,但是不起作用。
我拥有的:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Draw axes
\draw[->] (-4.1,0) -- (4.1,0) node[right] {$x$};
\draw[->] (0,-4.1) -- (0,4.1) node[above] {$y$};
% Draw the region for x < y
\fill[blue!20,opacity=0.5] (-4,-4) -- (-2,2) -- (4,4) -- cycle;
\draw[blue,thick] (-4,-4) -- (4,4) node[below right]{$x<y$};
\fill[red!20,opacity=0.5] (-2,-4) -- (-4,4) -- (2,4) -- cycle;
\draw[red,thick] (-2,-4) -- (2,4) node[below right] {$2x<y$};
\end{tikzpicture}
\end{document}
如何解决这个问题?
答案1
您有相等的限制,您只需要添加网格的其他角(并删除几个错误)。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Draw axes
\draw[->] (-4.1,0) -- (4.1,0) node[right] {$x$};
\draw[->] (0,-4.1) -- (0,4.1) node[above] {$y$};
% Draw the region for x < y
\fill[blue!20,opacity=0.5] (-4,-4) -- (4,4) -- (-4,4) -- cycle;
\draw[blue,thick] (-4,-4) -- (4,4) node[below right]{$x<y$};
\fill[red!20,opacity=0.5] (-2,-4) -- (2,4) -- (-4,4) -- (-4,-4) -- cycle;
\draw[red,thick] (-2,-4) -- (2,4) node[below right] {$2x<y$};
\end{tikzpicture}
\end{document}