我知道 LaTeX 有\vec{}
命令用箭头表示矢量,但我被教导用波浪线表示矢量。在 LaTeX 中也可以这样表示矢量吗?
答案1
答案2
使用 Ti 有两种可能性钾Z,\mathpalette
并且\fontdimen
为了使垂直偏移适应当前的数学字体和样式(即\displaystyle
、\textstyle
或\scriptstyle
)\scriptscriptstyle
。
1.
2.
对于第一个代码,对于有下划线的符号,“波浪线”会较低。对于第二个代码,对于所有符号,“波浪线”会从基线偏移相同的最小量(但这个量取决于当前的数学字体和样式),如果下划线的符号有异常低的下划线(参见整个許截图中带下划线的为矢量。1
对于那些也希望将波浪线放在数学表达式上方而不是下方的人,我将提供第二个代码的变体,该代码提供两个宏:一个将波浪线放在给定的数学表达式上方,另一个将波浪线放在数学表达式下方。
第一个代码
\documentclass{article}
\usepackage{xparse} % Not needed if the LaTeX format is at least 2020-10-01
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\makeatletter
% Command from egreg (https://tex.stackexchange.com/a/499972/73317)
\newcommand{\math@param}[3]{%
\fontdimen#3
\ifx#1\displaystyle\textfont#2
\else\ifx#1\textstyle\textfont#2
\else\ifx#1\scriptstyle\scriptfont#2
\else\scriptscriptfont#2 \fi\fi\fi
}
\newdimen\@my@yshift
\NewDocumentCommand{\myvec}{m}{\mathord{\mathpalette\@myvec{#1}}}
\newcommand*{\@myvec}[2]{%
\begin{tikzpicture}[baseline=(n.base)]
\node (n) [inner sep=0]
{\global\@my@yshift=-0.5\math@param{#1}{2}{5}%
$\m@th #1#2$};
\draw[decorate, decoration={snake, amplitude=0.3pt, segment length=2pt}]
([yshift=\@my@yshift]n.south west) -- ([yshift=\@my@yshift]n.south east);
\end{tikzpicture}%
}
\makeatother
\begin{document}
$\alpha \myvec{x} + \beta \myvec{y} + \gamma \myvec{z} = \myvec{0}$
\bigskip
$u_{\myvec{x}} = v^{\myvec{y}}$\qquad
$\myvec{u_{\myvec{x}}} = \myvec{v^{\myvec{y}}}$
\end{document}
第二个代码
\documentclass{article}
\usepackage{xparse} % Not needed if the LaTeX format is at least 2020-10-01
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\makeatletter
% Command from egreg (https://tex.stackexchange.com/a/499972/73317)
\newcommand{\math@param}[3]{%
\fontdimen#3
\ifx#1\displaystyle\textfont#2
\else\ifx#1\textstyle\textfont#2
\else\ifx#1\scriptstyle\scriptfont#2
\else\scriptscriptfont#2 \fi\fi\fi
}
\newdimen\@my@yshift
\NewDocumentCommand{\myvec}{m}{\mathord{\mathpalette\@myvec{#1}}}
\newcommand*{\@myvec}[2]{%
\begin{tikzpicture}[baseline=(n.base)]
\node (n) [inner sep=0]
{\global\@my@yshift=\math@param{#1}{2}{5}%
\vrule width 0pt height 0pt depth 0.5\@my@yshift\relax
$\m@th #1#2$};
% Make sure the snake is always drawn with a little shift below the south
% border of node n.
\draw[decorate, decoration={snake, amplitude=0.3pt, segment length=2pt}]
([yshift=-0.3\@my@yshift]n.south west) --
([yshift=-0.3\@my@yshift]n.south east);
\end{tikzpicture}%
}
\makeatother
\begin{document}
$\alpha \myvec{x} + \beta \myvec{y} + \gamma \myvec{z} = \myvec{0}$
\bigskip
$u_{\myvec{x}} = v^{\myvec{y}}$\qquad
$\myvec{u_{\myvec{x}}} = \myvec{v^{\myvec{y}}}$
\end{document}
高于或低于
下面是第二段代码的变体,它提供了两个宏:一个将波浪线放在给定的数学表达式上方,另一个将波浪线放在其下方:
\documentclass{article}
\usepackage{xparse} % Not needed if the LaTeX format is at least 2020-10-01
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\makeatletter
% Command from egreg (https://tex.stackexchange.com/a/499972/73317)
\newcommand{\math@param}[3]{%
\fontdimen#3
\ifx#1\displaystyle\textfont#2
\else\ifx#1\textstyle\textfont#2
\else\ifx#1\scriptstyle\scriptfont#2
\else\scriptscriptfont#2 \fi\fi\fi
}
\newdimen\@my@yshift
\NewDocumentCommand{\myvecBelow}{m}{\mathord{\mathpalette\@myvecBelow{#1}}}
\NewDocumentCommand{\myvecAbove}{m}{\mathord{\mathpalette\@myvecAbove{#1}}}
% Squiggly line below the math expression
\newcommand*{\@myvecBelow}[2]{%
\begin{tikzpicture}[baseline=(n.base)]
\node (n) [inner sep=0]
{\global\@my@yshift=\math@param{#1}{2}{5}%
\vrule width 0pt height 0pt depth 0.5\@my@yshift\relax
$\m@th #1#2$};
% Make sure the snake is always drawn with a little shift below the south
% border of node n.
\draw[decorate, decoration={snake, amplitude=0.3pt, segment length=2pt}]
([yshift=-0.3\@my@yshift]n.south west) --
([yshift=-0.3\@my@yshift]n.south east);
\end{tikzpicture}%
}
% Squiggly line above the math expression
\newcommand*{\@myvecAbove}[2]{%
\begin{tikzpicture}[baseline=(n.base)]
\node (n) [inner sep=0]
{\global\@my@yshift=\math@param{#1}{2}{5}%
\vrule width 0pt height 1.2\@my@yshift depth 0pt\relax
$\m@th #1#2$};
% Make sure the snake is always drawn with a little shift above the north
% border of node n.
\draw[decorate, decoration={snake, amplitude=0.3pt, segment length=2pt}]
([yshift=0.3\@my@yshift]n.north west) --
([yshift=0.3\@my@yshift]n.north east);
\end{tikzpicture}%
}
\makeatother
\newcommand{\testText}{%
$\alpha \myvec{x} + \beta \myvec{y} + \gamma \myvec{z} = \myvec{0}$
\bigskip
$u_{\myvec{x}} = v^{\myvec{y}}$\qquad
$\myvec{u_{\myvec{x}}} = \myvec{v^{\myvec{y}}}$%
}
\begin{document}
\begin{tabular}{ @{} p{0.3\linewidth} p{0.3\linewidth} @{}}
\let\myvec=\myvecBelow \testText &
\let\myvec=\myvecAbove \testText
\end{tabular}
\end{document}
脚注
- 可以使用节点文本中的
amsmath
和$\m@th #1\smash[b]{#2}$
而不是轻松恢复此功能。$\m@th #1#2$
答案3
我用向量包裹
在选项中选择波浪形。我发现它效果很好。
\documentclass{article}
\usepackage[wavy]{vector}
\begin{document}
\uvec{a} % gives a vector
\uuvec{a} % gives a unit vector
\end{document}
答案4
我undertilde
以前曾使用过该软件包来完成我的论文,但是其中有一个小错误,导致环境之间的间距equation
不一致align
。
这个问题如果你使用它,可以修复这个错误。