我正在尝试用公式解释我的步骤。问题是文本比环境中的行长\flalign*
,有什么方法可以让文本跨越多行同时保持对齐?
我希望它看起来像这样:
\documentclass[a4paper,oneside,article,leqno]{memoir}
\pagestyle{title}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[danish]{babel}\renewcommand{\danishhyphenmins}{22}
\renewcommand{\danishhyphenmins}{22}
\usepackage{sistyle, amsmath}
\usepackage{mathtools,amssymb}
\usepackage[margin=1.0in]{geometry}
\begin{document}
\begin{flalign*}
GKA(a,b)&=\frac{1}{n}\sum\limits_{i=1}^{n}(y_i-(ax_i+b))^2 &&\text{Anvend hjælpesætning b.}\\
&=\frac{1}{n}\sum\limits_{i=1}^{n}(\underbrace{(y_i-\bar{y})}_\text{s}-\underbrace{a(x_i-\bar{x})}_\text{t}+\underbrace{(\bar{y}-(a\bar{x}+b)}_\text{u})^2&&\text{Anvend omskrivning 2.}\\
&=\frac{1}{n}\sum\limits_{i=1}^{n}
\begin{pmatrix*}[l]
\vphantom{\frac{1}{n}\sum\limits_{i=1}^{n}}\underbrace{(y_i-\bar{y})^2}_\text{$s^2$}+\underbrace{a^2(x_i-\bar{x})^2}_\text{$t^2$}+\underbrace{(\bar{y}-(a\bar{x}+b))^2}_\text{$u^2$}\\
\vphantom{\frac{1}{n}\sum\limits_{i=1}^{n}}-\underbrace{2a(y_i-\bar{y})(x_i-\bar{x})}_\text{2st}+\underbrace{2(y_i-\bar{y})(\bar{y}-(a\bar{x}+b))}_\text{2su}\\
\vphantom{\frac{1}{n}\sum\limits_{i=1}^{n}}-\underbrace{2a(x_i-\bar{x})(\bar{y}-(a\bar{x}+b))}_\text{2tu}
\end{pmatrix*}&&\text{Gang med $\frac{1}{n}\sum\limits_{i=1}^{n}$ og brug hjælpesætning a.}\\
&=\frac{1}{n}\sum\limits_{i=1}^{n}(y_i-\bar{y})^2+\frac{1}{n}a^2\sum\limits_{i=1}^{n}(x_i-\bar{x})^2+\frac{1}{n}\sum\limits_{i=1}^{n}(\bar{y}-(a\bar{x}+b))^2&&\text{Brug at $V_1=$ gennemsnittet af $x_i$-erne}\\
&\quad-2a\cdot\frac{1}{n}\sum\limits_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})+2(\bar{y}-(a\bar{x}+b))\cdot\frac{1}{n}\sum\limits_{i=1}^{n}(y_i-\bar{y})\\
&\quad-2a(\bar{y}-(a\bar{x}+b))\cdot\frac{1}{n}\sum\limits_{i=1}^{n}(x_i-\bar{x})\\
&=V_2+a^2V_1+\frac{1}{n}\cdot n(\bar{y}-a\bar{x}-b)^2-2Ca+0-0\\
&=V_1\cdot a^2-2Ca+V_2+(\bar{y}-a\bar{x}-b)^2\\
&=f(a)+g(a,b)
\end{flalign*}
\end{document}
答案1
除了将应该自动换行的说明性文字放置在\parbox
具有适当宽度的文本中(在下面的代码中,我选择了 4.5 厘米),并将其内容设置为右对齐模式(以避免单词间出现较大的间隙)之外,您可能还希望消除所有不需要的\text
指令,并删除除一个\limits
修饰符之外的所有修饰符;在显示数学模式下,\sum
并\sum\limits
产生完全相同的输出。另外,由于GKA
可能不代表名为 、 和 的变量的乘积G
,K
因此A
您应该将该术语写为\mathit{GKA}
或\mathrm{GKA}
。
\documentclass[a4paper,oneside,article,leqno]{memoir}
\pagestyle{title}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[danish]{babel}
\renewcommand{\danishhyphenmins}{22}
\usepackage{sistyle, mathtools, amssymb}
\usepackage[margin=1.0in]{geometry}
\newcommand\textbox[2]{\parbox{#1}{\raggedright #2}}
\newcommand\tallstrut{\vphantom{\sum\limits_{i=1}^{n}}} % tall typographic strut
\begin{document}
\begin{flalign*}
\mathit{GKA}(a,b)
&=\frac{1}{n}\sum_{i=1}^{n}(y_i-(ax_i+b))^2
&&\text{Anvend hjælpesætning b.}\\
&=\frac{1}{n}\sum_{i=1}^{n} \bigl(\,
{\underbrace{(y_i-\bar{y})}_{s}}
-{\underbrace{a(x_i-\bar{x})}_{t}}
+{\underbrace{(\bar{y}-(a\bar{x}+b)}_{u}}\,\bigr)^2
&&\text{Anvend omskrivning 2.}\\
&=\frac{1}{n}\sum_{i=1}^{n}
\begin{pmatrix*}[l]
{\underbrace{(y_i-\bar{y})^2}_{s^2}}+
{\underbrace{a^2(x_i-\bar{x})^2}_{t^2}}+
{\underbrace{(\bar{y}-(a\bar{x}+b))^2}_{u^2}}\\
\tallstrut-{\underbrace{2a(y_i-\bar{y})(x_i-\bar{x})}_{2st}}
+{\underbrace{2(y_i-\bar{y})(\bar{y}-(a\bar{x}+b))}_{2su}}\\
\tallstrut-{\underbrace{2a(x_i-\bar{x})(\bar{y}-(a\bar{x}+b))}_{2tu}}
\end{pmatrix*}
&&\textbox{4.5cm}{Gang med $\frac{1}{n}\sum_{i=1}^{n}$
og brug hjælpesætning a.}\\
&=\frac{1}{n}\sum_{i=1}^{n}(y_i-\bar{y})^2+
\frac{1}{n}a^2\sum_{i=1}^{n}(x_i-\bar{x})^2+
\frac{1}{n}\sum_{i=1}^{n}(\bar{y}-(a\bar{x}+b))^2
&&\textbox{4.5cm}{Brug at $V_1=$ gennemsnittet af $x_i$-erne}\\
&\quad-2a\frac{1}{n}\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})
+2(\bar{y}-(a\bar{x}+b))\frac{1}{n}\sum_{i=1}^{n}(y_i-\bar{y})\\
&\quad-2a(\bar{y}-(a\bar{x}+b))\frac{1}{n}\sum_{i=1}^{n}(x_i-\bar{x})\\
&=V_2+a^2V_1+\frac{1}{n} n(\bar{y}-a\bar{x}-b)^2-2Ca+0-0\\
&=V_1 a^2-2Ca+V_2+(\bar{y}-a\bar{x}-b)^2\\
&=f(a)+g(a,b)
\end{flalign*}
\end{document}
答案2
这是一种使用\parbox
es 和脚注大小的文本的方法。Il 还减小了矩阵的大小,环境medsize
为nccmath
。
请注意,如果您加载mathtools
,则不必加载amsmath
,因为此包会为您完成此操作。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
%\usepackage{sistyle, amsmath}
\usepackage{mathtools,amssymb, nccmath}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[danish]{babel}
\renewcommand{\danishhyphenmins}{22}
\renewcommand{\danishhyphenmins}{22}
\begin{document}
\begin{flalign*}
GKA(a,b)&=\frac{1}{n}\sum\limits_{i=1}^{n}(y_i-(ax_i+b))^2 & & & &\text{\footnotesize Anvend hjælpesætning b.} \\
&=\frac{1}{n}\sum\limits_{i=1}^{n}(\underbrace{(y_i-\bar{y})}_\text{s}-\underbrace{a(x_i-\bar{x})}_\text{t}+\underbrace{(\bar{y}-(a\bar{x}+b)}_\text{u})^2 & & & &\text{\footnotesize Anvend omskrivning 2.} \\
&=\frac{1}{n}\sum\limits_{i=1}^{n}
\mathrlap{\begin{medsize}\begin{pmatrix*}[l]
\vphantom{\frac{1}{n}\sum\limits_{i=1}^{n}}\underbrace{(y_i-\bar{y})^2}_{s^2}{} + a^2\underbrace{(x_i-\bar{x})^2}_{t^2} +\underbrace{(\bar{y}-(a\bar{x}+b))^2}_{u^2} \\
\vphantom{\frac{1}{n}\sum\limits_{i=1}^{n}}-\underbrace{2a(y_i-\bar{y})(x_i-\bar{x})}_{2st} + \underbrace{2(y_i-\bar{y})(\bar{y})-(a\bar{x}+b)}_{2su} \\
\vphantom{\frac{1}{n}\sum\limits_{i=1}^{n}}-\underbrace{2a(x_i-\bar{x})(\bar{y})-(a\bar{x}+b))}_{2tu}
\end{pmatrix*}\end{medsize}} & & & & \parbox[t]{4cm}{\footnotesize Gang med $\frac{1}{n}\sum\limits_{i=1}^{n}$ og brug hjælpesætning a.}\\
& =\!\mathrlap{\begin{aligned}[t]\frac{1}{n} & \sum_{i=1}^{n}(y_i-\bar{y})^2
+ \frac{1}{n}a^2\sum_{i=1}^{n}(x_i-\bar{x})^2 + \frac{1}{n}\sum_{i=1}^{n}(\bar{y}-(a\bar{x}+b))^2 & \\
&-2a\cdot\smash{\frac{1}{n}\sum_{i=1}^{n}}(x_i-\bar{x})(y_i-\bar{y})\\
& + 2(\bar{y}-(a\bar{x}+b)) \cdot\frac{1}{n}\sum_{i=1}^{n} (y_i-\bar{y}) -2a(\bar{y}-(a\bar{x}+b))\cdot\frac{1}{n}\sum_{i=1}^{n}(x_i-\bar{x})
\end{aligned}}& & & & \parbox[t]{4cm}{\footnotesize Brug at $V_1=$ gennemsnittet af $x_i$-erne. \\ Some text. Some text. Some text. Some text}\\[-0.5ex]
&=V_2+a^2V_1+\frac{1}{n}\cdot n(\bar{y}-a\bar{x}-b)^2-2Ca+0-0\\
&=V_1\cdot a^2-2Ca+V_2+(\bar{y}-a\bar{x}-b)^2\\
&=f(a)+g(a,b)
\end{flalign*}
\end{document}