该mathtools
软件包提供了很棒的\cramped
命令,可以强制使用紧凑的上下标样式。也许这是一个坏习惯,但当我意识到指数会扰乱行距时,我倾向于用该命令包装整个内联公式。
但是,我不得不注意到,这似乎会影响公式中正常符号的间距,尤其是可能会对换行产生非常不良的影响。在下面的例子中,LaTeX 允许压缩到刚好足以将未拥挤的内容放入略小于自然宽度的框中。但是,如果整个公式都包裹在内\cramped{}
,它似乎会影响符号之间空间的可压缩性。据我所知,尽管字形本身是相同的,但将公式放入相同的空间中已不再可能。
有什么方法可以强制\cramped
仅影响下标和上标,而不影响其他一切?
\documentclass{article}
\usepackage{mathtools}
\pagestyle{empty}
\begin{document}
\setlength{\parskip}{1em}
\settowidth{\dimen0}{Test: $1 - 2^{-(\lambda-1)}$.}
\setlength{\dimen1}{0.985\dimen0}
nothing cramped:\\
\framebox{\parbox{\dimen0}{Test: $1 - 2^{-(\lambda-1)}$.}}
\framebox{\parbox{\dimen1}{Test: $1 - 2^{-(\lambda-1)}$.}}
everything cramped:\\
\framebox{\parbox{\dimen0}{Test: $\cramped{1 - 2^{-(\lambda-1)}}$.}}
\framebox{\parbox{\dimen1}{Test: $\cramped{1 - 2^{-(\lambda-1)}}$.}}
only second term cramped:\\
\framebox{\parbox{\dimen0}{Test: $1 - \cramped{2^{-(\lambda-1)}}$.}}
\framebox{\parbox{\dimen1}{Test: $1 - \cramped{2^{-(\lambda-1)}}$.}}
\settowidth{\dimen0}{Test: $1 - 2$.}
\setlength{\dimen1}{0.985\dimen0}
without su[b,p]scripts, nothing cramped:\\
\framebox{\parbox{\dimen0}{Test: $1 - 2$.}}
\framebox{\parbox{\dimen1}{Test: $1 - 2$.}}
without su[b,p]scripts, everything cramped:\\
\framebox{\parbox{\dimen0}{Test: $\cramped{1 - 2}$.}}
\framebox{\parbox{\dimen1}{Test: $\cramped{1 - 2}$.}}
\end{document}
答案1
的参数被排版为子公式,因此其中的空格被冻结;这与和\cramped
发生的情况相同。\left
\right
因此,减号周围的空格\cramped{1-2}
不再灵活,结果肯定看起来是错误的。出于同样的原因,\left
应该\right
绝不用于内联数学。
当然,在 中也会得到刚性空间$\sqrt{a-1}$
,但这并不是什么大问题,因为根式将子公式与上下文隔离开来。它是相同因为\cramped
,因为这个技巧用于\radical0
做它的事情。
我认为你想太多了。请看下面的例子,其中\lineskip
比通常的 1pt 大得多,只是为了清楚地看到它是否起作用。你可以看到它只在情况 5 中使用(其中出现了可怕的\left
和\right
)。仔细比较数字 1 和 2;在使用前者时\cramped
,后者具有正常的文本样式:我没有看到任何改进(实际上我认为数字 1 比数字 2 更差)。线条既有上升部,也有下降部。
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\lineskip=20pt % for better seeing if it's used
1.\ Some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
$\cramped{2^{-(\lambda-1)}}$
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
2.\ Some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
$2^{-(\lambda-1)}$
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
3.\ Some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
$2^{-(\lambda^2-1)}$
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
4.\ Some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
$2^{-(\sum_i\lambda_i^2-1)}$
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
5.\ Some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
$2^{-\left(\sum_i\lambda_i^2-1\right)}$
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
some silly text some silly text some silly text some silly text
\end{document}
说实话,我很幸运:如果我在第 4 项中将公式上方的“some”改为“sygge”,只是为了有连续的下降部分,我得到了
有人可能会不同意。如果我加上\cramped
,画面就变成了
我只会在文档的最终修订中担心这个问题,并且\cramped
只在真正需要的地方应用,因为存在上述冲突。
如果您愿意切换到 LuaLaTeX,您可以\cramped
通过使用数学样式更改来定义一个不会冻结空间的更好的宏。
\documentclass{article}
\usepackage{amsmath}
\newcommand{\changemathstyle}[1]{%
\ifcase#1\relax
\displaystyle\or
\crampeddisplaystyle\or
\textstyle\or
\crampedtextstyle\or
\scriptstyle\or
\crampedscriptstyle\or
\scriptscriptstyle\or
\crampedscriptscriptstyle
\fi
}
\newcommand\cramped[1]{%
\ifodd\mathstyle\relax
% we're already in a cramped style
#1%
\else
\edef\currentstyle{\mathstyle}%
\changemathstyle{\numexpr\mathstyle+1}%
#1%
\changemathstyle{\currentstyle}%
\fi
}
\begin{document}
\setlength{\parskip}{1em}
\settowidth{\dimen0}{Test: $1 - 2^{-(\lambda-1)}$.}
\setlength{\dimen1}{0.985\dimen0}
nothing cramped:\\
\framebox{\parbox{\dimen0}{Test: $1 - 2^{-(\lambda-1)}$.}}
\framebox{\parbox{\dimen1}{Test: $1 - 2^{-(\lambda-1)}$.}}
everything cramped:\\
\framebox{\parbox{\dimen0}{Test: $\cramped{1 - 2^{-(\lambda-1)}}$.}}
\framebox{\parbox{\dimen1}{Test: $\cramped{1 - 2^{-(\lambda-1)}}$.}}
only second term cramped:\\
\framebox{\parbox{\dimen0}{Test: $1 - \cramped{2^{-(\lambda-1)}}$.}}
\framebox{\parbox{\dimen1}{Test: $1 - \cramped{2^{-(\lambda-1)}}$.}}
\settowidth{\dimen0}{Test: $1 - 2$.}
\setlength{\dimen1}{0.985\dimen0}
without su[b,p]scripts, nothing cramped:\\
\framebox{\parbox{\dimen0}{Test: $1 - 2$.}}
\framebox{\parbox{\dimen1}{Test: $1 - 2$.}}
without su[b,p]scripts, everything cramped:\\
\framebox{\parbox{\dimen0}{Test: $\cramped{1 - 2}$.}}
\framebox{\parbox{\dimen1}{Test: $\cramped{1 - 2}$.}}
\end{document}