可能重复:
LaTeX 命令后的空格
我已经做了几个非常短的命令,它们可以工作,但遗憾的是它们后面的间距是错误的。
\newcommand{\yaksen}{$y$-aksen}
\newcommand{\xaksen}{$x$-aksen}
\newcommand{\zaksen}{$z$-aksen}
这不会在命令后产生空格,所以如果我输入
this is an example \yaksen, is the norwegian term for the y-axis.
and the \zaksen is perpendicular to both the \xaksen and the \yaksen.
输出为
this is an example y-aksen, is the norwegian term for the y-axis.
and the z-aksenis perpendicular to both the x-aksenand the y-aksen.
但是,在命令后添加空格。像这样
\newcommand{\yaksen}{$y$-aksen }
\newcommand{\xaksen}{$x$-aksen }
\newcommand{\zaksen}{$z$-aksen }
产生这个
this is an example y-aksen , is the norwegian term for the y-axis.
and the z-aksen is perpendicular to both the x-aksen and the y-aksen .
有没有简单的方法可以得到正确的间距?我想我读过一些相关内容,但我的搜索毫无结果。
答案1
您需要使用\xspace
提供的xspace
包裹。它检查命令序列后面的字符是否是空格,并相应地插入空格:
\documentclass{article}
\usepackage{xspace}% http://ctan.org/pkg/xspace
\newcommand{\yaksen}{$y$-aksen\xspace}
\newcommand{\xaksen}{$x$-aksen\xspace}
\newcommand{\zaksen}{$z$-aksen\xspace}
\begin{document}
this is an example \yaksen, is the norwegian term for the y-axis.
and the \zaksen is perpendicular to both the \xaksen and the \yaksen.
\end{document}