填充由多条线包围的区域并添加文本

填充由多条线包围的区域并添加文本

我对 Tex 还很陌生,正在尝试使用 tikz 包绘制图形。

这是我写的代码

\documentclass{article}
\usepackage{tikz}
\begin{document}
\ifx\du\undefined
  \newlength{\du}
\fi
\setlength{\du}{15\unitlength}
\begin{tikzpicture}
\pgftransformxscale{1}
\pgftransformyscale{-1}
\pgfsetlinewidth{0.1\du}
\draw (0\du,0\du)--(13\du,-13\du);
\draw (0\du,0\du)--(4\du,-1\du);
\draw (4\du,-1\du)--(9\du,-5\du);
\draw (9\du,-5\du)--(11\du,-8\du);
\draw (11\du,-8\du)--(13\du,-13\du);
\node[anchor=west] at (7\du,-5\du){some text};
\end{tikzpicture}
\end{document}

我正在尝试填充这些线条所限定的区域并且同时使“一些文本”可见。

有人可以帮忙吗?

答案1

正如我所理解的,你正在寻找什么,这里有一个解决方案,摆脱这些不需要的低级 pgf 线并相应地修改 y 坐标以避免这种情况y 变换形状

灌装区域

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \ifx\du\undefined
      \newlength{\du}
    \fi
    \setlength{\du}{15\unitlength}
    \begin{tikzpicture}
        \draw[line width=0.1\du, fill=pink] (0\du,0\du)--(13\du,13\du) -- (11\du,8\du) -- (9\du,5\du) -- (4\du,1\du) -- cycle;
        \node at (7\du,5\du){some text};
    \end{tikzpicture}
\end{document}

答案2

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\newcommand{\du}{15pt}
\draw[fill=cyan,very thick] (0,0) -- (13*\du,13*\du) -- (11*\du,8*\du) -- (9*\du,5*\du)  -- (4*\du,\du) -- cycle;
\node[anchor=west, red, font=\large] at (7*\du,5*\du){some text};
\end{tikzpicture}
\end{document}

带文本的青色形状

相关内容