梯形上的箭头

梯形上的箭头

我从网站上拼凑了两段代码,以获得一个带箭头的梯形。我让箭头和梯形的线条重合,但看起来有点乱。我无法将箭头的代码放入梯形图中,我想要这个带箭头的梯形。我的 mwe 如下

在此处输入图片描述

% !TeX program = xelatex
% !TeX spellcheck = en_GB
\documentclass[11pt,addpoints]{exam}
\usepackage{pgfplots}
\usepackage{geometry}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric,angles,quotes}% needed for trapzium 

\begin{document}
    
\scalebox{1.25}{
    \hspace*{-1.5cm}    \begin{tikzpicture}[scale=2, my angle/.style={font=\scriptsize, draw, angle eccentricity=1.75, angle radius=3mm}, very thick,decoration={
            markings,
            mark=at position 0.5 with {\arrow{> >}}}                  ]
        \node (a) [trapezium, trapezium angle=60, minimum width=50mm, draw, thick, label=above:8 cm, label=below:16 cm, label=right:8cm, label=left:8cm ] {};
        \draw [densely dashed] (a.north west) coordinate (a nw) -- (a nw |- a.south) node [midway,right] { 4 cm } coordinate (a1) (a.north east) coordinate (a ne) -- (a ne |- a.south) node [midway,left] {$h$} coordinate (a2);
        \draw (a nw |- a.south) ++(0,1.5mm) -| ++(-1.5mm,-1.5mm) (a ne |- a.south) ++(0,1.5mm) -| ++(1.5mm,-1.5mm);
        \coordinate (a blc) at (a.bottom left corner);
        \coordinate (a brc) at (a.bottom right corner);
                \draw[postaction={decorate}] (-0.5,0.58)--(0.5,0.58);
                \draw[postaction={decorate}] (-0.5,-0.58)--(0.5,-0.58);
    \end{tikzpicture}
}           
    
\end{document}

答案1

只需在装饰路径中使用\path而不是 即可。\draw

我还添加了其他一些小改动:

  • 不要使用带空格的节点名称,它会让你的生活变得毫无意义的复杂化
  • 如果你命名了一个坐标,就用那个名字,之后,这是最简单的
  • 正确缩放 tikzpicture(无需使用\scalebox

这是我的解决方案:

% !TeX program = xelatex
% !TeX spellcheck = en_GB
\documentclass[11pt,addpoints]{exam}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{geometry}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric,angles,quotes}% needed for trapzium 

\begin{document}
\begin{center}    
\begin{tikzpicture}[scale=.5, very thick,
            decoration={
            markings,
            mark=at position 0.55 with {\arrow{>>}}}          ]
    \node[trapezium, trapezium angle=60, minimum width=50mm, draw, thick, label=above:8 cm, label=below:16 cm, label=right:8 cm, label=left:8 cm ] (a) {};
    \draw [densely dashed] (a.north west) coordinate (aNW) -- (aNW |- a.south) node [midway, right] { 4 cm } coordinate (a1) 
        (a.north east) coordinate (aNE) -- (aNE |- a.south) node [midway, left] {$h$} coordinate (a2);
    \draw (a1) ++(0,7.5mm) -| ++(-7.5mm,-7.5mm) 
        (a2) ++(0,7.5mm) -| ++(7.5mm,-7.5mm);
    \path[postaction={decorate}] (aNW) -- (aNE);
    \path[postaction={decorate}] (a1) -- (a2);
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

答案2

虽然 TikZnode很方便,但在这种情况下trapzium节点不必要地复杂。一种简单的方法是使用纯 TikZ。

在此处输入图片描述

\documentclass[11pt,addpoints]{exam}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[scale=.5,thick,declare function = {a=sqrt(48);},
    decoration={markings,mark=at position 0.5 with {\arrow{>>}}},
]

\path 
(0,0)  coordinate (Bt)
(-4,0) coordinate (A)
(0,a)  coordinate (B)
(8,a)  coordinate (C)
(12,0) coordinate (D)
(8,0)  coordinate (Ct);

\begin{scope}[nodes={midway}]

\fill[lightgray!50!white] 
(Bt) rectangle +(135:1)
(Ct) rectangle +(45:1);

\draw[densely dashed] (B)--(Bt) (C)--(Ct) node[left]{$h$};
\draw[postaction={decorate}] (B)--(C) node[above]{$8$ cm};
\draw[postaction={decorate}] (A)--(D) node[below]{$16$ cm};
\draw 
(A)--(B) node[above,sloped]{$8$ cm}
(C)--(D) node[above,sloped]{$8$ cm};
\end{scope}
\end{tikzpicture}
\end{document}

相关内容