我有一个方程式:constant = f(parm, parm, ...),其中包含一个很长的参数列表,我想在每行末尾自动换行(在逗号后),以便第二行和后续行(参数)在方程式的右侧对齐。但我不想手动为每行插入换行符和 \quads。有办法实现吗?
以下是我希望它看起来的样子,注意另一个错误,即行首(例如第二行)的负数被渲染为“-19...”,而不是“-19...”。我也很乐意修复这个错误 :) :
这是生成上述内容的源代码(包括手动换行符和 \quads 以产生所需的格式)
\begin{aligned}
0 &= P(3,1152921504606846976,120,(0,\allowbreak2^{59},\allowbreak-3^{3}\cdot2^{57},\allowbreak3\cdot2^{59},\allowbreak5^{3}\cdot2^{56},\allowbreak-13\cdot2^{58},\allowbreak0,\allowbreak \\
&\quad -19\cdot2^{58},\allowbreak3^{3}\cdot2^{54},\allowbreak2^{55},\allowbreak0,\allowbreak3\cdot31\cdot2^{53},\allowbreak0,\allowbreak2^{53},\allowbreak-7^{2}\cdot2^{52},\allowbreak-19\cdot2^{54},\allowbreak0,\allowbreak-13\cdot2^{52},\allowbreak0,\allowbreak \\
&\quad -113\cdot2^{49},\allowbreak-3^{3}\cdot2^{48},\allowbreak2^{49},\allowbreak0,\allowbreak-5^{3}\cdot2^{47},\allowbreak-5^{3}\cdot2^{46},\allowbreak2^{47},\allowbreak-3^{3}\cdot2^{45},\allowbreak3\cdot2^{47},\allowbreak0,\allowbreak-13\cdot2^{46},\allowbreak \\
&\quad 0,\allowbreak-19\cdot2^{46},\allowbreak3^{3}\cdot2^{42},\allowbreak2^{43},\allowbreak5^{3}\cdot2^{41},\allowbreak3\cdot31\cdot2^{41},\allowbreak0,\allowbreak2^{41},\allowbreak3^{3}\cdot2^{39},\allowbreak-3^{3}\cdot2^{39},\allowbreak0,\allowbreak-13\cdot2^{40},\allowbreak \\
&\quad 0,\allowbreak3\cdot2^{39},\allowbreak7^{2}\cdot2^{37},\allowbreak2^{37},\allowbreak0,\allowbreak-5^{3}\cdot2^{35},\allowbreak0,\allowbreak2^{35},\allowbreak-3^{3}\cdot2^{33},\allowbreak3\cdot2^{35},\allowbreak0,\allowbreak-13\cdot2^{34},\allowbreak-5^{3}\cdot2^{31},\allowbreak \\
&\quad -19\cdot2^{34},\allowbreak3^{3}\cdot2^{30},\allowbreak2^{31},\allowbreak0,\allowbreak-2^{34},\allowbreak0,\allowbreak2^{29},\allowbreak3^{3}\cdot2^{27},\allowbreak-19\cdot2^{30},\allowbreak-5^{3}\cdot2^{26},\allowbreak-13\cdot2^{28},\allowbreak0,\allowbreak \\
&\quad 3\cdot2^{27},\allowbreak-3^{3}\cdot2^{24},\allowbreak2^{25},\allowbreak0,\allowbreak-5^{3}\cdot2^{23},\allowbreak0,\allowbreak2^{23},\allowbreak7^{2}\cdot2^{22},\allowbreak3\cdot2^{23},\allowbreak0,\allowbreak-13\cdot2^{22},\allowbreak0,\allowbreak-3^{3}\cdot2^{19},\allowbreak \\
&\quad 3^{3}\cdot2^{18},\allowbreak2^{19},\allowbreak0,\allowbreak3\cdot31\cdot2^{17},\allowbreak5^{3}\cdot2^{16},\allowbreak2^{17},\allowbreak3^{3}\cdot2^{15},\allowbreak-19\cdot2^{18},\allowbreak0,\allowbreak-13\cdot2^{16},\allowbreak0,\allowbreak3\cdot2^{15},\allowbreak \\
&\quad -3^{3}\cdot2^{12},\allowbreak2^{13},\allowbreak-5^{3}\cdot2^{11},\allowbreak-5^{3}\cdot2^{11},\allowbreak0,\allowbreak2^{11},\allowbreak-3^{3}\cdot2^{9},\allowbreak-113\cdot2^{9},\allowbreak0,\allowbreak-13\cdot2^{10},\allowbreak0,\allowbreak \\
&\quad -19\cdot2^{10},\allowbreak-7^{2}\cdot2^{7},\allowbreak2^{7},\allowbreak0,\allowbreak3\cdot31\cdot2^{5},\allowbreak0,\allowbreak2^{5},\allowbreak3^{3}\cdot2^{3},\allowbreak-19\cdot2^{6},\allowbreak0,\allowbreak-13\cdot2^{4},\allowbreak5^{3}\cdot2,\allowbreak3\cdot2^{3},\allowbreak \\
&\quad -3^{3},\allowbreak2,\allowbreak0,\allowbreak0))
\end{aligned}
答案1
我不想手动
\quad
为每一行插入换行符和 s
您可以将整个方程式放在\parbox
(a) 自动悬挂缩进和 (b) 抑制完全对齐中。这样可以\\ &\quad
从代码中删除所有实例——它们不再需要。
我已将宽度设置\parbox
为0.85\textwidth
生成以下屏幕截图;请随意修改此选择。
\documentclass{article}
\begin{document}
\begin{equation}
\parbox[b]{0.85\textwidth}{\raggedright\hangafter=1\hangindent=2em$\displaystyle
%% I've deleted all `\\ &\quad` directives
0 = P(3,1152921504606846976,120,(0,\allowbreak2^{59},\allowbreak-3^{3}\cdot2^{57},\allowbreak3\cdot2^{59},\allowbreak5^{3}\cdot2^{56},\allowbreak-13\cdot2^{58},\allowbreak0,\allowbreak-19\cdot2^{58},\allowbreak3^{3}\cdot2^{54},\allowbreak2^{55},\allowbreak0,\allowbreak3\cdot31\cdot2^{53},\allowbreak0,\allowbreak2^{53},\allowbreak-7^{2}\cdot2^{52},\allowbreak-19\cdot2^{54},\allowbreak0,\allowbreak-13\cdot2^{52},\allowbreak0,\allowbreak-113\cdot2^{49},\allowbreak-3^{3}\cdot2^{48},\allowbreak2^{49},\allowbreak0,\allowbreak-5^{3}\cdot2^{47},\allowbreak-5^{3}\cdot2^{46},\allowbreak2^{47},\allowbreak-3^{3}\cdot2^{45},\allowbreak3\cdot2^{47},\allowbreak0,\allowbreak-13\cdot2^{46},\allowbreak0,\allowbreak-19\cdot2^{46},\allowbreak3^{3}\cdot2^{42},\allowbreak2^{43},\allowbreak5^{3}\cdot2^{41},\allowbreak3\cdot31\cdot2^{41},\allowbreak0,\allowbreak2^{41},\allowbreak3^{3}\cdot2^{39},\allowbreak-3^{3}\cdot2^{39},\allowbreak0,\allowbreak-13\cdot2^{40},\allowbreak0,\allowbreak3\cdot2^{39},\allowbreak7^{2}\cdot2^{37},\allowbreak2^{37},\allowbreak0,\allowbreak-5^{3}\cdot2^{35},\allowbreak0,\allowbreak2^{35},\allowbreak-3^{3}\cdot2^{33},\allowbreak3\cdot2^{35},\allowbreak0,\allowbreak-13\cdot2^{34},\allowbreak-5^{3}\cdot2^{31},\allowbreak-19\cdot2^{34},\allowbreak3^{3}\cdot2^{30},\allowbreak2^{31},\allowbreak0,\allowbreak-2^{34},\allowbreak0,\allowbreak2^{29},\allowbreak3^{3}\cdot2^{27},\allowbreak-19\cdot2^{30},\allowbreak-5^{3}\cdot2^{26},\allowbreak-13\cdot2^{28},\allowbreak0,\allowbreak3\cdot2^{27},\allowbreak-3^{3}\cdot2^{24},\allowbreak2^{25},\allowbreak0,\allowbreak-5^{3}\cdot2^{23},\allowbreak0,\allowbreak2^{23},\allowbreak7^{2}\cdot2^{22},\allowbreak3\cdot2^{23},\allowbreak0,\allowbreak-13\cdot2^{22},\allowbreak0,\allowbreak-3^{3}\cdot2^{19},\allowbreak3^{3}\cdot2^{18},\allowbreak2^{19},\allowbreak0,\allowbreak3\cdot31\cdot2^{17},\allowbreak5^{3}\cdot2^{16},\allowbreak2^{17},\allowbreak3^{3}\cdot2^{15},\allowbreak-19\cdot2^{18},\allowbreak0,\allowbreak-13\cdot2^{16},\allowbreak0,\allowbreak3\cdot2^{15},\allowbreak-3^{3}\cdot2^{12},\allowbreak2^{13},\allowbreak-5^{3}\cdot2^{11},\allowbreak-5^{3}\cdot2^{11},\allowbreak0,\allowbreak2^{11},\allowbreak-3^{3}\cdot2^{9},\allowbreak-113\cdot2^{9},\allowbreak0,\allowbreak-13\cdot2^{10},\allowbreak0,\allowbreak-19\cdot2^{10},\allowbreak-7^{2}\cdot2^{7},\allowbreak2^{7},\allowbreak0,\allowbreak3\cdot31\cdot2^{5},\allowbreak0,\allowbreak2^{5},\allowbreak3^{3}\cdot2^{3},\allowbreak-19\cdot2^{6},\allowbreak0,\allowbreak-13\cdot2^{4},\allowbreak5^{3}\cdot2,\allowbreak3\cdot2^{3},\allowbreak-3^{3},\allowbreak2,\allowbreak0,\allowbreak0))
$}
\end{equation}
\end{document}
附录:如果您可以使用 LuaLaTeX 来编译您的文档,您可以使用 Lua 的功能“动态”string.gsub
插入所有 122 条 [!]指令,从而大大减少输入代码的阻塞。\allowbreak
% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{luacode} % for '\luastringN' macro ("unexpanded string-ification")
\begin{document}
\begin{equation}
\parbox[b]{0.85\textwidth}{\raggedright\hangafter=1\hangindent=2em$\displaystyle
0 = \directlua {
s=\luastringN{P(3,1152921504606846976,120,(0,2^{59},-3^{3}\cdot2^{57},3\cdot2^{59},5^{3}\cdot2^{56},-13\cdot2^{58},0,-19\cdot2^{58},3^{3}\cdot2^{54},2^{55},0,3\cdot31\cdot2^{53},0,2^{53},-7^{2}\cdot2^{52},-19\cdot2^{54},0,-13\cdot2^{52},0,-113\cdot2^{49},-3^{3}\cdot2^{48},2^{49},0,-5^{3}\cdot2^{47},-5^{3}\cdot2^{46},2^{47},-3^{3}\cdot2^{45},3\cdot2^{47},0,-13\cdot2^{46},0,-19\cdot2^{46},3^{3}\cdot2^{42},2^{43},5^{3}\cdot2^{41},3\cdot31\cdot2^{41},0,2^{41},3^{3}\cdot2^{39},-3^{3}\cdot2^{39},0,-13\cdot2^{40},0,3\cdot2^{39},7^{2}\cdot2^{37},2^{37},0,-5^{3}\cdot2^{35},0,2^{35},-3^{3}\cdot2^{33},3\cdot2^{35},0,-13\cdot2^{34},-5^{3}\cdot2^{31},-19\cdot2^{34},3^{3}\cdot2^{30},2^{31},0,-2^{34},0,2^{29},3^{3}\cdot2^{27},-19\cdot2^{30},-5^{3}\cdot2^{26},-13\cdot2^{28},0,3\cdot2^{27},-3^{3}\cdot2^{24},2^{25},0,-5^{3}\cdot2^{23},0,2^{23},7^{2}\cdot2^{22},3\cdot2^{23},0,-13\cdot2^{22},0,-3^{3}\cdot2^{19},3^{3}\cdot2^{18},2^{19},0,3\cdot31\cdot2^{17},5^{3}\cdot2^{16},2^{17},3^{3}\cdot2^{15},-19\cdot2^{18},0,-13\cdot2^{16},0,3\cdot2^{15},-3^{3}\cdot2^{12},2^{13},-5^{3}\cdot2^{11},-5^{3}\cdot2^{11},0,2^{11},-3^{3}\cdot2^{9},-113\cdot2^{9},0,-13\cdot2^{10},0,-19\cdot2^{10},-7^{2}\cdot2^{7},2^{7},0,3\cdot31\cdot2^{5},0,2^{5},3^{3}\cdot2^{3},-19\cdot2^{6},0,-13\cdot2^{4},5^{3}\cdot2,3\cdot2^{3},-3^{3},2,0,0))}
tex.sprint ( ( string.gsub ( s , ',' , ',\\allowbreak' ) ) )
}
$}
\end{equation}
\end{document}
答案2
艰难的处境需要强有力的锤子。
\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum}
\begin{document}
\lipsum[1][1-4]
\[
% some local settings
\binoppenalty=10000 % no line break after \cdot
\mathchardef\comma=\mathcode`, % save the mathcode
\mathcode`,="8000 % make the comma math active
\thinmuskip=0mu
\begingroup\lccode`~=`,
\lowercase{\endgroup\def~}{%
\comma\allowbreak\hspace{3pt plus 2pt}%
}% define it to be a comma with possible line break followed by a flexible space
% now the formula; first a phantom for the alignment
\hphantom{0=P\bigl(}
\parbox{0.8\displaywidth}{\linespread{1.1}\selectfont % less compact typesetting
\makebox[0pt][r]{$0=P\bigl($}$
3, 1152921504606846976,120,(0, 2^{59}, -3^{3}\cdot2^{57}, 3\cdot2^{59},
5^{3}\cdot2^{56}, -13\cdot2^{58}, 0, -19\cdot2^{58}, 3^{3}\cdot2^{54},
2^{55}, 0, 3\cdot31\cdot2^{53}, 0, 2^{53}, -7^{2}\cdot2^{52},
-19\cdot2^{54}, 0, -13\cdot2^{52}, 0, -113\cdot2^{49}, -3^{3}\cdot2^{48},
2^{49}, 0, -5^{3}\cdot2^{47}, -5^{3}\cdot2^{46}, 2^{47}, -3^{3}\cdot2^{45},
3\cdot2^{47}, 0, -13\cdot2^{46}, 0, -19\cdot2^{46}, 3^{3}\cdot2^{42},
2^{43}, 5^{3}\cdot2^{41}, 3\cdot31\cdot2^{41}, 0, 2^{41}, 3^{3}\cdot2^{39},
-3^{3}\cdot2^{39}, 0, -13\cdot2^{40}, 0, 3\cdot2^{39}, 7^{2}\cdot2^{37},
2^{37}, 0, -5^{3}\cdot2^{35}, 0, 2^{35}, -3^{3}\cdot2^{33}, 3\cdot2^{35},
0, -13\cdot2^{34}, -5^{3}\cdot2^{31}, -19\cdot2^{34}, 3^{3}\cdot2^{30},
2^{31}, 0, -2^{34}, 0, 2^{29}, 3^{3}\cdot2^{27}, -19\cdot2^{30},
-5^{3}\cdot2^{26}, -13\cdot2^{28}, 0, 3\cdot2^{27}, -3^{3}\cdot2^{24},
2^{25}, 0, -5^{3}\cdot2^{23}, 0, 2^{23}, 7^{2}\cdot2^{22}, 3\cdot2^{23},
0, -13\cdot2^{22}, 0, -3^{3}\cdot2^{19}, 3^{3}\cdot2^{18}, 2^{19}, 0,
3\cdot31\cdot2^{17}, 5^{3}\cdot2^{16}, 2^{17}, 3^{3}\cdot2^{15},
-19\cdot2^{18}, 0, -13\cdot2^{16}, 0, 3\cdot2^{15}, -3^{3}\cdot2^{12},
2^{13}, -5^{3}\cdot2^{11}, -5^{3}\cdot2^{11}, 0, 2^{11}, -3^{3}\cdot2^{9},
-113\cdot2^{9}, 0, -13\cdot2^{10}, 0, -19\cdot2^{10}, -7^{2}\cdot2^{7},
2^{7}, 0, 3\cdot31\cdot2^{5}, 0, 2^{5}, 3^{3}\cdot2^{3}, -19\cdot2^{6}, 0,
-13\cdot2^{4}, 5^{3}\cdot2, 3\cdot2^{3}, -3^{3}, 2, 0, 0
)\bigr)$
}
\]
\lipsum[2][1-4]
\end{document}