如何在 tikz 电路中实现一致的字体大小?

如何在 tikz 电路中实现一致的字体大小?

使用 tikz 电路库创建电路时,对象可能具有各种不同的构造。可能有包含分数的标签,也可能有带标签的普通路径。我发现字体大小是可变的,这会使生成的电路难以阅读。

这是我的最小工作示例:

\documentclass{standalone}

\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{arrows,circuits.ee.IEC,positioning}

\begin{document}

\begin{tikzpicture}[circuit ee IEC,x=2cm,y=1.5cm,
every info/.style={font=\footnotesize},
small circuit symbols,
set inductor graphic=var inductor IEC graphic,
set diode graphic=var diode IEC graphic,
set make contact graphic= var make contact IEC graphic]
% Set the font size

% Let us start with some contacts:
\foreach \contact/\x in {0/0,2/3}
{
\node [contact] (upper contact \contact) at (\x,4) {};
\node [contact] (lower contact \contact) at (\x,0) {};
}
\node [coordinate] (upper right limit) at (6,4) {};
\node [coordinate] (lower right limit) at (6,0) {};

\draw (upper contact 0) to [current direction={near start,info=$I_1$},resistor={info={$\text{R}_1$}},inductor={near end,info={$\text{jX}_1$}}] (upper contact 2);
\draw (upper contact 2) to[current direction={near start,info=$\text{I}_2$},inductor={near end,info={$\text{jX}_2$}}] (upper right limit)
    to[resistor={info={$\frac{\text{R}_2}{\text{s}}$}}] (lower right limit)
    to (lower contact 2)
    to ++(0,1) coordinate (lower fork) {}
    -- ++(-1,0) to[resistor={info={$\text{R}_\text{m}$}}] ++(0,2)
    to ++(1,0) coordinate (upper fork) {}
    to [current direction'={info=$\text{I}_\text{m}$}] (upper contact 2);
\draw (upper fork) -- ++(1,0)
    to[inductor={info={$\text{jX}_\text{m}$}}] ++(0,-2)
    to (lower fork);
\draw[color=blue,thick,->] (upper contact 0) ++(0,-0.5) -- ++(0,-1.5) node[anchor=east] (spannung) {$\text{U}_1$} -- ++(0,-1.5);
\draw[color=blue,thick,->] (upper contact 2) ++(2,-0.5) -- ++(0,-1.5) node[anchor=east] (spannung) {$\text{U}_\text{Err}$} -- ++(0,-1.5);
\draw (lower contact 2) -- (lower contact 0);

\end{tikzpicture}

\end{document}

不同的字体大小...

U1和UErr电压标签比电阻和电感的标签大,右侧的R_2/s特别小。

现在,我可以将字体大小参数放在标签文本前面,就像在常规 LaTeX 文档中一样,但问题是每个文本元素的起始大小似乎不同,所以我必须通过反复试验来调整每个标签的大小。

如果我在 tikzpicture 环境的开始处放置类似 \large 的内容,那么只有 U1 和 UErr 标签会受到影响。

是否有一种简洁的方法来实现每个标签的一致字体大小?

答案1

电阻和电感标签较小是由适用于部件标签的样式 引起的every info/.style={font=\footnotesize}。要使所有文本的字体大小相同,请删除该样式,并在选项every node/.style={font=\large}中将其替换为tikzpicture。要使分数使用更大的文本,请使用\dfrac而不是\frac

\documentclass[border=5mm]{standalone}

\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{arrows,circuits.ee.IEC,positioning}

\begin{document}

\begin{tikzpicture}[circuit ee IEC,x=2cm,y=1.5cm,
every node/.style={font=\large},
small circuit symbols,
set inductor graphic=var inductor IEC graphic,
set diode graphic=var diode IEC graphic,
set make contact graphic= var make contact IEC graphic]
% Set the font size

% Let us start with some contacts:
\foreach \contact/\x in {0/0,2/3}
{
\node [contact] (upper contact \contact) at (\x,4) {};
\node [contact] (lower contact \contact) at (\x,0) {};
}
\node [coordinate] (upper right limit) at (6,4) {};
\node [coordinate] (lower right limit) at (6,0) {};

\draw (upper contact 0) to [current direction={near start,info=$I_1$},resistor={info={$\text{R}_1$}},inductor={near end,info={$\text{jX}_1$}}] (upper contact 2);
\draw (upper contact 2) to[current direction={near start,info=$\text{I}_2$},inductor={near end,info={$\text{jX}_2$}}] (upper right limit)
    to[resistor={info={$\dfrac{\text{R}_2}{\text{s}}$}}] (lower right limit)
    to (lower contact 2)
    to ++(0,1) coordinate (lower fork) {}
    -- ++(-1,0) to[resistor={info={$\text{R}_\text{m}$}}] ++(0,2)
    to ++(1,0) coordinate (upper fork) {}
    to [current direction'={info=$\text{I}_\text{m}$}] (upper contact 2);
\draw (upper fork) -- ++(1,0)
    to[inductor={info={$\text{jX}_\text{m}$}}] ++(0,-2)
    to (lower fork);
\draw[color=blue,thick,->] (upper contact 0) ++(0,-0.5) -- ++(0,-1.5) node[anchor=east] (spannung) {$\text{U}_1$} -- ++(0,-1.5);
\draw[color=blue,thick,->] (upper contact 2) ++(2,-0.5) -- ++(0,-1.5) node[anchor=east] (spannung) {$\text{U}_\text{Err}$} -- ++(0,-1.5);
\draw (lower contact 2) -- (lower contact 0);

\end{tikzpicture}

\end{document}

相关内容