带注释的矩形 tikz

带注释的矩形 tikz

这个答案我找到了以下创建带注释的立方体的代码:

\documentclass[border=5pt, multi, tikz]{standalone}
\usetikzlibrary{quotes,arrows.meta}
\begin{document}
\begin{tikzpicture}[every edge quotes/.append style={auto, text=blue}]
  \pgfmathsetmacro{\cubex}{5}
  \pgfmathsetmacro{\cubey}{1}
  \pgfmathsetmacro{\cubez}{3}
  \draw [draw=blue, every edge/.append style={draw=blue, densely dashed, opacity=.5}, fill=magenta]
    (0,0,0) coordinate (o) -- ++(-\cubex,0,0) coordinate (a) -- ++(0,-\cubey,0) coordinate (b) edge coordinate [pos=1] (g) ++(0,0,-\cubez)  -- ++(\cubex,0,0) coordinate (c) -- cycle
    (o) -- ++(0,0,-\cubez) coordinate (d) -- ++(0,-\cubey,0) coordinate (e) edge (g) -- (c) -- cycle
    (o) -- (a) -- ++(0,0,-\cubez) coordinate (f) edge (g) -- (d) -- cycle;
  \path [every edge/.append style={draw=blue, |-|}]
    (b) +(0,-5pt) coordinate (b1) edge ["30cm"'] (b1 -| c)
    (b) +(-5pt,0) coordinate (b2) edge ["5cm"] (b2 |- a)
    (c) +(3.5pt,-3.5pt) coordinate (c2) edge ["10cm"'] ([xshift=3.5pt,yshift=-3.5pt]e)
    ;
\end{tikzpicture}
\end{document}

我是 Latex 新手,我想调整代码,使其产生带注释的矩形。但是,不知何故我没能做到这一点。

答案1

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\rectx}{5}
\pgfmathsetmacro{\recty}{1}
\filldraw[blue, fill=magenta] (0,0) rectangle (\rectx,\recty);
\draw[blue, |-|, yshift=-5pt] (0,0) --node[below]{5cm} (\rectx,0);
\draw[blue, |-|, xshift=5pt] (\rectx,0) --node[right]{1cm} (\rectx,\recty);
\end{tikzpicture}
\end{document}

长度的矩形

相关内容