缩放方程以适合精确的页面宽度

问题描述 投票:37回答:3

我有一个方程,对于一条线只有一点点太宽。我真的想避免在下一行使用方程编号。你是如何实现这一目标的?目前我正在使用\small,但这太过分了。

请注意。我尝试了scaleboxfittowidth,但得到关于缺少\endgroup的错误。我也充分利用了\!。我希望有一个解决方案,允许我将正确的单线方程式缩放到页面的宽度。

这是一个例子(不是我的实际等式):Long equation

latex
3个回答
58
投票
\begin{equation}
\resizebox{.9\hsize}{!}{$A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z$}
\end{equation}

要么

\begin{equation}
\resizebox{.8\hsize}{!}{$A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z$}
\end{equation}

2
投票

graphicx package提供命令\resizebox{width}{height}{object}

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\hrule
%%%
\makeatletter%
\setlength{\@tempdima}{\the\columnwidth}% the, well columnwidth
\settowidth{\@tempdimb}{(\ref{Equ:TooLong})}% the width of the "(1)"
\addtolength{\@tempdima}{-\the\@tempdimb}% which cannot be used for the math
\addtolength{\@tempdima}{-1em}%
% There is probably some variable giving the required minimal distance
% between math and label, but because I do not know it I used 1em instead.
\addtolength{\@tempdima}{-1pt}% distance must be greater than "1em"
\xdef\Equ@width{\the\@tempdima}% space remaining for math
\begin{equation}%
\resizebox{\Equ@width}{!}{$\displaystyle{% to get everything inside "big"
 A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z}$}%
\label{Equ:TooLong}%
\end{equation}%
\makeatother%
%%%
\hrule
\end{document}

1
投票

我只是想要这种情况,只有超过\linewidth的线,即:稍微挤压长线。由于花了我几个小时来解决这个问题,我想在此处添加它。

我想强调的是,在LaTeX中缩放字体是一种致命的罪!在几乎所有情况下,都有更好的方法(例如multline包的mathtools)。所以有意识地使用它。

在这种特殊情况下,除了前导码之外,我对代码库没有任何影响,当我将其编译成电子书缩放的pdf时,有些行略微超出页面边界。

\usepackage{environ}         % provides \BODY
\usepackage{etoolbox}        % provides \ifdimcomp
\usepackage{graphicx}        % provides \resizebox

\newlength{\myl}
\let\origequation=\equation
\let\origendequation=\endequation

\RenewEnviron{equation}{
  \settowidth{\myl}{$\BODY$}                       % calculate width and save as \myl
  \origequation
  \ifdimcomp{\the\linewidth}{>}{\the\myl}
  {\ensuremath{\BODY}}                             % True
  {\resizebox{\linewidth}{!}{\ensuremath{\BODY}}}  % False
  \origendequation
}

之前before之后after

© www.soinside.com 2019 - 2024. All rights reserved.