尺寸线问题(TikZ)

尺寸线问题(TikZ)

我用 TikZ 画了这幅图。我怎样才能完成那条尺寸线?

\documentclass[border=2pt] {standalone}
%\usepackage{tikz}
%\usetikzlibrary{calc}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
%\usetikzlibrary{arrows.meta}
\begin{document}
\definecolor{uququq}{rgb}{0.25098039215686274,0.25098039215686274,0.25098039215686274}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=0.8cm,y=0.8cm]
\draw [color=black,fill=yellow,fill opacity=0.5] (2.0,0.0) circle (0.5cm);
\draw [line width=1.5pt] (0.0,6.0)-- (-2.0,0.0);
\draw [line width=1.5pt] (0.0,6.0)-- (2.0,0.0);
\draw [line width=1.0pt,dash pattern=on 4pt off 4pt] (2.0,0.0)-- (-2.0,0.0);
\draw [line width=1.0pt,dash pattern=on 4pt off 4pt] (0.0,6.0)-- (-0.003238033414928232,0.0);
%quote
\draw (-0.9300042508665818,6.310001416955528)-- (-2.930004250866582,0.3100014169555273);
%\draw (-2.0,-1.094507989900869)-- (2.0,-1.094507989900869);
\draw (-2.0,-1.094507989900869)-- (2.0,-1.094507989900869);
\draw (-2.0,-0.85)-- (-2.0,-1.35);
\draw (2.0,-0.85)-- (2.0,-1.35);
\begin{scriptsize}

\draw[color=black] (-2.0,3.229250320291161) node {\Large $x$ cm};
%\draw[color=black] (0.7988152988075463,3.0491975314248916) node {$f$};
\draw[color=black] (0.0,-0.7) node {\Large $y$ cm};
%\draw[color=black] (-0.21602769298415597,3.1474081435337657) node {$h$};
\end{scriptsize}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

如果您只需要这一个图形(而不是更多),那么您可以设置如下所示的快速样式(它需要arrows.meta):

\tikzset{
    quote/.style={{|[width=5mm]}-{|[width=5mm]}}
}

然后只需像这样编写命令(节点包含在路径中):

\draw[quote] (-0.9300042508665818,6.310001416955528) -- 
    (-2.930004250866582,0.3100014169555273) node[left, midway] {\Large $x$ cm};
\draw[quote] (-2.0,-1.094507989900869) -- 
    (2.0,-1.094507989900869) node[above, midway] {\Large $x$ cm};

您会得到这个(忽略错误的颜色):

在此处输入图片描述

完整代码如下:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta}

\definecolor{uququq}{rgb}{0.25098039215686274,0.25098039215686274,0.25098039215686274}

\tikzset{
    quote/.style={{|[width=5mm]}-{|[width=5mm]}}
}

\begin{document}
\begin{tikzpicture}[%
    line cap=round,line join=round,
    >=triangle 45,
    x=0.8cm,y=0.8cm,
    every node/.style={font=\scriptsize}]

\draw [fill=yellow, opacity=.5] (2.0,0.0) circle (0.5cm);
% Triangle
\draw [line width=1.5pt] (-2.0,0.0) -- (0.0,6.0) -- (2.0,0.0);
\draw [line width=1pt,densely dashed] (2.0,0.0)-- (-2.0,0.0);
\draw [line width=1pt,densely dashed] (0.0,6.0)-- (-0.003238033414928232,0.0);

\draw[quote] (-0.9300042508665818,6.310001416955528) -- 
    (-2.930004250866582,0.3100014169555273) node[left, midway] {$x$ cm};
\draw[quote] (-2.0,-1.094507989900869)-- (2.0,-1.094507989900869) node[above, midway] {$x$ cm};
\end{tikzpicture}
\end{document}

一些说明:

  1. \draw[color=black]您甚至不需要指定\draw[black],因为这是默认颜色。
  2. 如果您希望节点(所有节点)都有小文本,请将其添加到您的旁边tikzpicture

    \begin{tikzpicture}[every node/.style={font=\scriptsize}]
    ...
    
  3. 要小心,因为你把它们设置得很小,但你却写了... {\Large $x$ cm};

答案2

随着措施的使用arrow.meta和一些简化和修改的外观:

在此处输入图片描述

\documentclass[border=2pt,tikz] {standalone}
\usetikzlibrary{arrows.meta}
\definecolor{uququq}{rgb}{0.25098039215686274,0.25098039215686274,0.25098039215686274}

    \begin{document}
\begin{tikzpicture}[
    line cap=round, line join=round,
    quote/.style = {{Bar[width=3mm]}-{Bar[width=3mm]}},
    >={Straight Barb[]}, 
    x=0.8cm, y=0.8cm]
\draw[fill=yellow,fill opacity=0.5] (2.0,0.0) circle (0.5cm);
\draw[line width=1.5pt] (0.0,6.0)-- (-2.0,0.0) 
                        (0.0,6.0)-- (2.0,0.0);
\draw[line width=1.0pt,dash pattern=on 4pt off 4pt] 
                        (2.0,0.0)-- (-2.0,0.0)
                        (0.0,6.0)-- (-0.003238033414928232,0.0);
% measures
\draw[quote] (-0.9300042508665818,6.310001416955528)--
node[above,sloped] {$x$ cm}   (-2.930004250866582,0.3100014169555273);
\draw[quote] (-2.0,-1.094507989900869) --
node[above] {$x$ cm} (2.0,-1.094507989900869);
\end{tikzpicture}
    \end{document}

或者使用组合线头的替代方案:

在此处输入图片描述

其中quotes定义为:

quote/.style = {{Bar[width=3mm]Straight Barb[]}-{Straight Barb[]Bar[width=3mm]}},

相关内容