如何使用 tikz 绘制电压表和电流表

如何使用 tikz 绘制电压表和电流表

我如何使用 tikz 绘制带有指针和刻度的电压表和电流表,以便学生可以读取数值? 在此处输入图片描述

答案1

像这样:

在此处输入图片描述

代码:

\documentclass[border=10pt]{standalone}

\usepackage{tikz}

\begin{document}
    
    \begin{tikzpicture}
        \fill (0,0) circle(8pt);
        \draw[line width=3pt] (39:6) arc (39:141:6);
        \foreach \an in {140,138,...,40}
            \draw[line width=2pt] (\an:6)--(\an:6.3);
        \foreach \an [count=\c] in {140,130,...,40}{
            \pgfmathsetmacro{\s}{int(\c-1)}
            \draw[line width=3] (\an:6)--(\an:6.5) node[pos=1.7] () {\huge \bfseries \s};
        }
        \draw[-stealth,line width=4pt] (0,0)--(113:5.9);
        \node at (0,3) {\bfseries \huge V};
    \end{tikzpicture}\qquad
    \begin{tikzpicture}
        \fill (0,0) circle(8pt);
        \draw[line width=2pt] (29:6) arc (29:151:6);
        \foreach \an in {140,130,...,40}
            \draw[line width=2pt] (\an:5.8)--(\an:6);
        \foreach \an/\lab  in {140/0.0,120/0.2,100/0.4,80/0.6,60/0.8,40/1.0}{
            
            \draw[line width=3] (\an:6)--(\an:5.6) node[pos=1.9] () {\Large \bfseries \lab};
        }
        \draw[-stealth,line width=4pt] (0,0)--(113:5);
        \node at (0,3) {\bfseries \huge A};
    \end{tikzpicture}

\end{document}

添加:我修改了前面的代码,定义了两个新命令:\vt\am,每个命令都有一个数字参数。此参数是测量值,因此每个图片上的大箭头指向所需的值。如果我们在代码中写入\vt{6.2}电压表上的大箭头指向值 6.2 V。这是我重新访问的代码:

\documentclass{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{tikz,lipsum}
\newcommand{\vt}[1]{
\begin{tikzpicture}
    \filldraw[fill=cyan!30,draw=blue,line width=5pt] (-6.5,-1) rectangle (6.5,8);
\fill (0,0) circle(8pt);
\draw[line width=3pt] (39:6) arc (39:141:6);
\foreach \an in {140,138,...,40}
\draw[line width=2pt] (\an:6)--(\an:6.3);
\foreach \an [count=\c] in {140,130,...,40}{
    \pgfmathsetmacro{\s}{int(\c-1)}
    \draw[line width=3] (\an:6)--(\an:6.5) node[pos=1.7] () {\huge \bfseries \s};
}
\draw[-stealth,line width=4pt] (0,0)--({140-10*#1}:5.9);
\node at (0,3) {\bfseries \huge V};
\end{tikzpicture}
}

\newcommand{\am}[1]{
    \begin{tikzpicture}
        \filldraw[fill=cyan!30,draw=blue,line width=5pt] (-6.5,-1) rectangle (6.5,8);
        \fill (0,0) circle(8pt);
        \draw[line width=2pt] (29:6) arc (29:151:6);
        \foreach \an in {140,130,...,40}
        \draw[line width=2pt] (\an:5.8)--(\an:6);
        \foreach \an/\lab  in {140/0.0,120/0.2,100/0.4,80/0.6,60/0.8,40/1.0}{
            
            \draw[line width=3] (\an:6)--(\an:5.6) node[pos=1.9] () {\Large \bfseries \lab};
        }
        \draw[-stealth,line width=4pt] (0,0)--({140-100*#1}:5);
        \node at (0,3) {\bfseries \huge A};
    \end{tikzpicture}
}
\begin{document}
    \lipsum[1][1-5]\\
    \begin{center}
        \vt{6.2}
    \end{center}
    \lipsum[2][3-12]\\
    \begin{center}
        \am{.3}
    \end{center}
\end{document}

输出结果如下:

在此处输入图片描述

相关内容