“$d=2$ 维” 中的间距

“$d=2$ 维” 中的间距

如果我想写像“d=3-Dimension”这样的短语,正确的间距是多少?

如果我只是写$d=1$-dimensional,等号周围的间距对我来说似乎太宽了?

在此处输入图片描述

(也许“-”周围的间距可能有点太小了?)

(我想用这个公式巧妙地提醒读者,$d$本文中调用了输入维度,同时告知当前章节仅处理一维情况。)

例子:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\newcommand{\R}{\mathbb{R}}
\begin{document}
Define a neural network $\mathcal{NN}_\theta$ as a function from $X=\R^d$ to $Y=\R$ s.t.

\[
\mathcal{NN}_\theta (x)=\dots defintion \dots \quad\forall x\in X
\]

For the rest of the section only the the $d=1$-dimensional case is considered.
\end{document}

(PS:可能还应该添加一些反对连字符的内容,就像这里提到的那样:避免在“2-D”中使用连字符。如果答案中已经包含了这一点就好了。)

答案1

在@Mico 的代码基础上,借助xparse,我提出了一个\Diml命令,其中 = 符号周围的间距更紧密,并且参数以更自然的方式输入,因为 d = 某个值。当然,您可以轻松调整间距以适合您的喜好。

\documentclass{article}
\usepackage{amsmath} %
\usepackage{xparse}
\newcommand{\Diml}[1]{\dimlargs{#1}}
\NewDocumentCommand{\dimlargs}{>{\SplitArgument{1}{=}}m}
{\dimlargsaux#1}
\NewDocumentCommand{\dimlargsaux}{mm}{%
 \text{$ #1\mkern2mu{=}\mkern2mu#2 $\nobreakdash-dimensional}}%

\begin{document}

$\Diml{d=1},\;\Diml{e = n }$

\end{document} 

在此处输入图片描述

答案2

假设您已经加载了该amsmath包,我将利用其指令来确保和\nobreakdash之间永远不会出现换行符。2-dimensional

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath} % for \nobreakdash and \text macros
%% Define a macro that takes an optional argument;
%% default value of optional argument is '2'.
\newcommand\diml[1][2]{\text{$#1$\nobreakdash-dimensional}}

\begin{document}
$d=\diml$, $d=\diml[3]$, $d=\diml[n]$
\end{document}

相关内容