如何在 siunitx 中添加“lb”并显示变量而不是常量

如何在 siunitx 中添加“lb”并显示变量而不是常量

我有这个简单的水箱,我想以这样的速率写入:

r 加仑/分钟

1/4 磅/加仑

(问题是我无法改变常量{},它必须用常量填充,因此我通过$r$ 在第二个括号内使用来欺骗它)

(第二个问题是没有\lb,因此我使用\text{lb}

\usepackage{mathptmx} % To emulate your `font`
\usepackage{siunitx} % To write units correctly 
\usepackage{tikz} % Obvious
\usetikzlibrary{decorations.pathmorphing} % To decorate the surface of water
\usetikzlibrary{arrows.meta} % The newer options for arrows (PGF 3.0)
\colorlet{water}{cyan!25} % Define color for the water
%--------------------------
% Dimensions of the tank
\def\tankwidth{6}
\def\tankheight{4}
\def\waterheight{2.2} % Water height 
%--------------------------
\tikzset{
    faucet/.pic={ % Define a 'pic' for the water inlet and outlet (PGF 3.0)
        \fill[water](-0.25,-0.25) rectangle (0.25,0.25);
        \draw[line width=1pt](-0.25,-0.25)--(0.25,-0.25) (-0.25,0.25)--(0.25,0.25);
    },
    myarrow/.tip={Stealth[scale=1.5]}, % Define a style for the tip of arrow
    surface water/.style= % style for border of water surface
    {decoration={random steps,segment length=1mm,amplitude=0.5mm}, decorate}
}

\begin{document}
\begin{tikzpicture}
    % Water fill (I filled first so that way it is in the background)
    \fill[water] decorate[surface water]{(\tankwidth,\waterheight) -- (0,\waterheight)}--(0,0) -- (\tankwidth,0) -- cycle;
    
    % Tank
    \draw[line width=1pt] (0,0) rectangle (\tankwidth,\tankheight);
    
    \coordinate (entrance) at (0,\tankheight-0.7);
    \coordinate (exit) at (\tankwidth,0.7);
    
    \pic[xshift=-2.5mm+0.5pt] at (entrance) {faucet}; % water inlet (0.5pt is half of line width) 
    \pic[xshift=2.5mm-0.5pt] at (exit) {faucet}; % outlet water
    
    % Entrance label (with `siunitx`)
    \node[align=right,left=1cm] (inlet-unit) at (entrance)  {\SI[per-mode=symbol]{6}{\liter\per\minute}\\\SI[per-mode=symbol]{0.1}{\kilogram\per\liter}};
    %[align=...] in the last node is necessary for splitting in two lines with `\\`
    \draw[-myarrow](inlet-unit)--([xshift=-5mm]entrance);
    
    % Exit label
    \node[align=left,right=1cm] (outlet-unit) at (exit) {\SI[per-mode=symbol]{5}{\liter\per\minute}};
    \draw[-myarrow]([xshift=5mm]exit)--(outlet-unit);
    
    \draw[|-|] ([xshift=-2mm]0,0) -- node[fill=white,inner xsep=0]{$V_{0}$}([xshift=-2mm]0,\waterheight); 
    
    % Fall water (i use `parabola` operation, it's more realistic, bacause it's a fall water) 
    \fill[water] ([shift={(0.5pt,-2.5mm)}]entrance) parabola (0.3*\tankwidth,1pt) -- 
    (0.5*\tankwidth,1pt) parabola[bend at end] ([shift={(0.5pt,2.5mm)}]entrance);
    
    % Inner labels
    \path (0.5*\tankwidth,\tankheight)--(0.5*\tankwidth,0)
    node[pos=0.2] {$x(t)$}
    node[pos=0.5] {?\,L}
    node[pos=0.8] {$x(0)=\SI{0}{\kilogram}$};
\end{tikzpicture}
\end{document}

答案1

  1. 声明你的单位
  2. 像使用文档中的其他内容一样使用它们。
  3. 禁用的解析过程siunitx并在的参数中使用您需要的任何内容\qty

代码

\documentclass{article}
\usepackage{siunitx}
\DeclareSIUnit{\lb}{lb}
\DeclareSIUnit{\gal}{gal}
\begin{document}
$\qty[parse-numbers=false, per-mode=symbol]{r}{\gal\per\minute}$

$\qty[parse-numbers=false, per-mode=fraction]{\frac{1}{4}}{\lb\per\gal}$
\end{document}

输出

在此处输入图片描述

相关内容