在群里看见画阴影部分,有个大佬说用foreach+clip,翻了书,不会,来请教一下。代码如下
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
  \begin{tikzpicture}
    \draw[-latex] (0, 0) node[below left]{O}-- (5, 0);
    \draw[-latex] (0, 0) -- (0, 5);
    \draw (0, 0) -- (4, 0) -- (4, 4) -- (0, 4);
    \draw[clip] (1.5, 0) -- (4, 2.5) -- (4, 4) -- (2.5, 4) -- (0, 1.5) -- (0, 0) -- cycle;
  \end{tikzpicture}
  \begin{tikzpicture}
    \draw[-latex] (0, 0) node[below left]{O}-- (5, 0);
    \draw[-latex] (0, 0) -- (0, 5);
    \draw (0, 0) -- (4, 0) -- (4, 4) -- (0, 4);
    \path[draw, pattern=vertical lines] (1.5, 0) -- (4, 2.5) -- (4, 4) -- (2.5, 4) -- (0, 1.5) -- (0, 0) -- cycle;
  \end{tikzpicture}
\end{document}                    
                理解了clip的作用,就写出来了,应该是clip+foreach而不是foreach+clip
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
  \begin{tikzpicture}
    \draw[-latex] (0, 0) node[below left]{O}-- (5, 0);
    \draw[-latex] (0, 0) -- (0, 5);
    \draw (0, 0) -- (4, 0) -- (4, 4) -- (0, 4);
    \draw[clip] (1.5, 0) -- (4, 2.5) -- (4, 4) -- (2.5, 4) -- (0, 1.5) -- (0, 0) -- cycle;
    \foreach \x in {0, 0.1,...,5}{
      \draw (\x, 0) -- (\x, 5);
    }
  \end{tikzpicture}
  \begin{tikzpicture}
    \draw[-latex] (0, 0) node[below left]{O}-- (5, 0);
    \draw[-latex] (0, 0) -- (0, 5);
    \draw (0, 0) -- (4, 0) -- (4, 4) -- (0, 4);
    \path[draw, pattern=vertical lines] (1.5, 0) -- (4, 2.5) -- (4, 4) -- (2.5, 4) -- (0, 1.5) -- (0, 0) -- cycle;
  \end{tikzpicture}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
结果如下