对齐长方程

对齐长方程

我知道以前有人问过这类问题,但我还没有找到解决这个问题的方法。我有以下长代码:

\documentclass[12pt,a4paper,twoside]{report}
\usepackage{amsmath,amsthm,mathtools}
\begin{document}
\begin{align*}
f_{32}=&x^{32} +12198x^{31} +2314465x^{30} -12105775188x^{29} +5363823023298x^{28} +112255815323746\\
&8x^{27} -1190957568896565522x^{26} +209082600175304589984x^{25} +22989403151925296937\\
&003x^{24} -4914900851027091491992374x^{23} +187314971305181007593402091x^{22} +185143\\
&5573081259757991725916x^{21} -177112654221172660874138268072x^{20} +43926953348772\\
&854958076288336008x^{19} -8069925182155695353376402378426972x^{18} +68958542881736\\
&5840411341429649636128x^{17} -23740614034450231197314286171021009177x^{16} -155324\\
&9919261394918300632995703368436966x^{15} +25870940606770260632602122011252618896\\
&6887x^{14} -14511399786110161424357109505278330297341724x^{13} +1463537885226408987\\
&41319428949250465719024858x^{12} +32750278659384832647975670671061051222933180188\\
&x^{11} -2286974864798158343157856729712480557839267556386x^{10} +5932631975811948614\\
&5828221766889960355126201846912x^9 +6575146802218754701624346687966744930450753\\
&36579853x^8 -105521419234945522100651241454885243895292286754573898x^7 +40112381\\
&65200337244745440754326620606602486694989793197x^6 -886067081083651605769689130\\
&22740501751611649852083140204x^5 +127506445946767356976971370547537041919975453\\
&7492781650348x^4 -12161035278122430054818848726808537446643676687311798879424x^3\\
 &+74518442436178190616718411536731834197503633925706662198320x^2 -2668848018838\\
&36189911937468492568061745225307284731520442304x +4266570219847726085064384156\\
&02232517825896105800369395838016
\end{align*}
\end{document}

\\这里的问题是,我尝试通过在适当的位置插入和来调整方程的末尾,&将方程拆分为多行,但不幸的是,它看起来很乱,根本没有对齐。我插入了一个带有红色圆圈的图像来标识我的问题。 在此处输入图片描述

答案1

我认为,为了保持这个多项式表达式的可读性,你应该在几乎所有项中每行只写一个项。当然,不要在长整数项中引入换行符。

在此处输入图片描述

\documentclass[12pt,a4paper,twoside]{report}
\usepackage{amsmath}
\allowdisplaybreaks % allow page breaks
\begin{document}
\begin{align*}
f_{32} &=x^{32} +12198x^{31} \\
&\quad+2314465x^{30} \\
&\quad-12105775188x^{29} \\
&\quad+5363823023298x^{28} \\
&\quad+1122558153237468x^{27} \\
&\quad -1190957568896565522x^{26} \\
&\quad+209082600175304589984x^{25}\\ 
&\quad+22989403151925296937003x^{24} \\
&\quad-4914900851027091491992374x^{23}\\ 
&\quad+187314971305181007593402091x^{22} \\
&\quad+1851435573081259757991725916x^{21}\\ 
&\quad-177112654221172660874138268072x^{20} \\
&\quad+43926953348772854958076288336008x^{19}\\ 
&\quad-8069925182155695353376402378426972x^{18} \\
&\quad+689585428817365840411341429649636128x^{17}\\ 
&\quad-23740614034450231197314286171021009177x^{16} \\
&\quad-1553249919261394918300632995703368436966x^{15}\\ 
&\quad+258709406067702606326021220112526188966887x^{14}\\ 
&\quad-14511399786110161424357109505278330297341724x^{13}\\ 
&\quad+146353788522640898741319428949250465719024858x^{12}\\ 
&\quad+32750278659384832647975670671061051222933180188x^{11}\\ 
&\quad-2286974864798158343157856729712480557839267556386x^{10}\\ 
&\quad+59326319758119486145828221766889960355126201846912x^9\\ 
&\quad+657514680221875470162434668796674493045075336579853x^8\\ 
&\quad-105521419234945522100651241454885243895292286754573898x^7\\ 
&\quad+4011238165200337244745440754326620606602486694989793197x^6\\ 
&\quad-88606708108365160576968913022740501751611649852083140204x^5 \\
&\quad+1275064459467673569769713705475370419199754537492781650348x^4 \\
&\quad-12161035278122430054818848726808537446643676687311798879424x^3\\
&\quad+74518442436178190616718411536731834197503633925706662198320x^2 \\
&\quad-266884801883836189911937468492568061745225307284731520442304x \\
&\quad+426657021984772608506438415602232517825896105800369395838016
\end{align*}
\end{document}

附录回应 OP 留下的评论:如果已知方程式必须(并且将)适合一页纸,则您可能希望使用环境array而不是align*环境。前者的优势在于行距更紧密,这使得完整的多项式表达式更有可能确实适合一页纸。

在此处输入图片描述

\documentclass[12pt,a4paper,twoside]{report}
\begin{document}
\appendix
\section*{Appendix: More information on \boldmath $ f_{32}$}

The function $f_{32}$ is given by the following 32nd-degree polynomial in $x$:
\[
\begin{array}{@{}r@{}l@{}}
f_{32} ={} &x^{32}\\
&{}+12198\,x^{31}\\
&{}+2314465\,x^{30}\\
&{}-12105775188\,x^{29}\\
&{}+5363823023298\,x^{28}\\
&{}+1122558153237468\,x^{27}\\
&{}-1190957568896565522\,x^{26}\\
&{}+209082600175304589984\,x^{25}\\ 
&{}+22989403151925296937003\,x^{24}\\
&{}-4914900851027091491992374\,x^{23}\\ 
&{}+187314971305181007593402091\,x^{22}\\
&{}+1851435573081259757991725916\,x^{21}\\ 
&{}-177112654221172660874138268072\,x^{20}\\
&{}+43926953348772854958076288336008\,x^{19}\\ 
&{}-8069925182155695353376402378426972\,x^{18}\\
&{}+689585428817365840411341429649636128\,x^{17}\\ 
&{}-23740614034450231197314286171021009177\,x^{16}\\
&{}-1553249919261394918300632995703368436966\,x^{15}\\ 
&{}+258709406067702606326021220112526188966887\,x^{14}\\ 
&{}-14511399786110161424357109505278330297341724\,x^{13}\\ 
&{}+146353788522640898741319428949250465719024858\,x^{12}\\ 
&{}+32750278659384832647975670671061051222933180188\,x^{11}\\ 
&{}-2286974864798158343157856729712480557839267556386\,x^{10}\\ 
&{}+59326319758119486145828221766889960355126201846912\,x^9\\ 
&{}+657514680221875470162434668796674493045075336579853\,x^8\\ 
&{}-105521419234945522100651241454885243895292286754573898\,x^7\\ 
&{}+4011238165200337244745440754326620606602486694989793197\,x^6\\ 
&{}-88606708108365160576968913022740501751611649852083140204\,x^5\\
&{}+1275064459467673569769713705475370419199754537492781650348\,x^4\\
&{}-12161035278122430054818848726808537446643676687311798879424\,x^3\\
&{}+74518442436178190616718411536731834197503633925706662198320\,x^2\\
&{}-266884801883836189911937468492568061745225307284731520442304\,x\\
&{}+426657021984772608506438415602232517825896105800369395838016
\end{array}
\]
\end{document}

答案2

@Mico 的解决方案更合适,但为了找出错位的原因,我给出了这个答案。问题是你的方程完全偏离了边界,如果你加载,\usepackage[showframe]{geometry}你会看到这个:

在此处输入图片描述

因此,真正的问题是换行。使用环境时,align您必须正确换行。解决此问题的另一种方法是使用breqn提供自动换行的包。请参阅下面的 MWE 和编译结果。

\documentclass[12pt,a4paper,twoside]{report}
\usepackage{amsmath,amsthm,mathtools,breqn}
\usepackage[showframe]{geometry}
\begin{document}
\begin{dmath*}
f_{32} = x^{32} +12198x^{31} +2314465x^{30} -12105775188x^{29} +5363823023298x^    {28} +112255815323746
8x^{27} -1190957568896565522x^{26} +209082600175304589984x^{25}     +22989403151925296937
003x^{24} -4914900851027091491992374x^{23} +187314971305181007593402091x^{22}     +185143
5573081259757991725916x^{21} -177112654221172660874138268072x^{20}     +43926953348772
854958076288336008x^{19} -8069925182155695353376402378426972x^{18}     +68958542881736
5840411341429649636128x^{17} -23740614034450231197314286171021009177x^{16}     -155324
9919261394918300632995703368436966x^{15} +25870940606770260632602122011252618896
6887x^{14} -14511399786110161424357109505278330297341724x^{13}     +1463537885226408987
41319428949250465719024858x^{12}     +32750278659384832647975670671061051222933180188
x^{11} -2286974864798158343157856729712480557839267556386x^{10}     +5932631975811948614
5828221766889960355126201846912x^9 +6575146802218754701624346687966744930450753
36579853x^8 -105521419234945522100651241454885243895292286754573898x^7 +40112381
65200337244745440754326620606602486694989793197x^6 -886067081083651605769689130
22740501751611649852083140204x^5 +127506445946767356976971370547537041919975453
7492781650348x^4 -12161035278122430054818848726808537446643676687311798879424x^3
 +74518442436178190616718411536731834197503633925706662198320x^2 -2668848018838
36189911937468492568061745225307284731520442304x +4266570219847726085064384156
02232517825896105800369395838016
\end{dmath*}
\end{document}

在此处输入图片描述

这个结果与 Mico 建议的非常相似。

答案3

您可以通过定义合适的环境来使用更自然的输入;此外,此环境可以为字体大小命令提供可选参数,以防\normalsize术语太宽。

\documentclass[12pt,a4paper,twoside]{report}
\usepackage{amsmath,amsthm,mathtools}

\usepackage{lipsum} % just for the example

\makeatletter
\newenvironment{longpoly}[2][\normalsize]
 {\par\nopagebreak\vspace{\abovedisplayskip}% end a par and emulate a display
  \setlength{\parindent}{0pt}%
  #1% a font size declaration
  \raggedright
  \sbox\z@{\quad$#2={}$}% measure the left-hand side
  \setlength{\leftskip}{\wd\z@}%
  \setplusandminus
  $% start math mode
  \hspace*{-\wd\z@}%
  \quad#2=}
 {$\par\vspace{\belowdisplayskip}}
\mathchardef\std@plus=\mathcode`+
\def\setplusandminus{%
  \begingroup\lccode`~=`- \lowercase{\endgroup\def~}{\penalty-\@M\std@minus\nobreak}
  \begingroup\lccode`~=`+ \lowercase{\endgroup\def~}{\penalty-\@M\std@plus\nobreak}
  \mathcode`+="8000
  \mathcode`-="8000
}
\makeatother

\begin{document}

\lipsum*[1-2]
\begin{longpoly}[\footnotesize]{f_{32}}
x^{32} 
+12198x^{31} 
+2314465x^{30} 
-12105775188x^{29} 
+5363823023298x^{28} 
+1122558153237468x^{27} 
-1190957568896565522x^{26} 
+209082600175304589984x^{25} 
+22989403151925296937003x^{24} 
-4914900851027091491992374x^{23}
+187314971305181007593402091x^{22} 
+1851435573081259757991725916x^{21} 
-177112654221172660874138268072x^{20} 
+43926953348772854958076288336008x^{19} 
-8069925182155695353376402378426972x^{18} 
+689585428817365840411341429649636128x^{17} 
-23740614034450231197314286171021009177x^{16} 
-1553249919261394918300632995703368436966x^{15} 
+258709406067702606326021220112526188966887x^{14} 
-14511399786110161424357109505278330297341724x^{13} 
+146353788522640898741319428949250465719024858x^{12} 
+32750278659384832647975670671061051222933180188x^{11} 
-2286974864798158343157856729712480557839267556386x^{10} 
+59326319758119486145828221766889960355126201846912x^9 
+657514680221875470162434668796674493045075336579853x^8 
-105521419234945522100651241454885243895292286754573898x^7 
+4011238165200337244745440754326620606602486694989793197x^6 
-88606708108365160576968913022740501751611649852083140204x^5 
+1275064459467673569769713705475370419199754537492781650348x^4 
-12161035278122430054818848726808537446643676687311798879424x^3
+74518442436178190616718411536731834197503633925706662198320x^2 
-266884801883836189911937468492568061745225307284731520442304x 
+426657021984772608506438415602232517825896105800369395838016
\end{longpoly}
\lipsum[4]

\end{document}

在此处输入图片描述

相关内容