Multiple alignment in math mode without much space
For multiple alignment points you can use alignat
:
\documentclass[a4paper, abstracton, bibtotocnumbered,liststotoc,12pt]{scrartcl}
%%%%% Betriebssystemabhängige Eingabedekodierung
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc} %% für Windows
\usepackage[ngerman]{babel}
\usepackage{amsthm}
\usepackage{mathtools}
\newcommand{\matr}[1]{\mathbf{#1}}
\newcommand{\X}{\matr{X}} %Matrix von X
\newcommand{\y}{\matr{y}} %y als voller Vektor
\newcommand{\Xt}{\X^\mathbf{T}} %Matrix von X
\newcommand{\x}{\matr{x}}%Regressor von X
\newcommand{\xt}{\x^\mathbf{T}}%Regressor von X
\newcommand{\betahat}{\hat{\beta}} %betahat
\begin{document}
\begin{alignat*}{2}
\Xt\y-\Xt\X\betahat & = \lambda s\\
\Leftrightarrow \underbrace{\Xt \y}_{p \times 1} & = \underbrace{\vphantom{ \Xt \y } \lambda s}_{p \times 1}, & \quad & s \in [-1,1]^{p} \\
\intertext{\textnormal{Das $j$-te Element entspricht}}
\xt_{j}\y &= \lambda s_j, & \quad & s_j \in [-1,1] \Leftrightarrow \lambda s_j \in [-\lambda, \lambda] \\
\Leftrightarrow |\xt_{j}\y| &\leq \lambda, & \quad & \forall j \in \{1,\dots,p\}
\end{alignat*}
\end{document}
The flalign
environment’s name means full length align, which means that the whole line width will be used when there is more than one alignment point.
In order to control the alignment you can use alignat
or just align
if you don't want to bother.
%%%%% Dokumentenklasse mit verschiedenen Attributen
\documentclass[a4paper, abstracton,12pt]{scrartcl}
%%%%% Betriebssystemabhängige Eingabedekodierung
\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc} %% für Windows
\usepackage[ngerman]{babel}
\usepackage{amsthm}
\usepackage{mathtools}
\newcommand{\matr}[1]{\mathbf{#1}}
\newcommand{\X}{\matr{X}} %Matrix von X
\newcommand{\y}{\matr{y}} %y als voller Vektor
\newcommand{\Xt}{\X^\mathbf{T}} %Matrix von X
\newcommand{\x}{\matr{x}}%Regressor von X
\newcommand{\xt}{\x^\mathbf{T}}%Regressor von X
\newcommand{\betahat}{\hat{\beta}} %betahat
\begin{document}
\section{\texttt{alignat}}
\begin{alignat*}{2}
\Xt\y-\Xt\X\betahat
&= \lambda s\\
\Leftrightarrow {\underbrace{\Xt \y}_{p \times 1}}
&= {\underbrace{\vphantom{ \Xt \y } \lambda s}_{p \times 1}},
&\quad& s \in [-1,1]^{p} \\
\intertext{Das $j$-te Element entspricht}
\xt_{j}\y
&= \lambda s_j,
&\quad& s_j \in [-1,1] \Leftrightarrow \lambda s_j \in [-\lambda, \lambda] \\
\Leftrightarrow |\xt_{j}\y|
&\leq \lambda,
&\quad& \forall j \in \{1,\dots,p\}
\end{alignat*}
\section{\texttt{align}}
\begin{align*}
\Xt\y-\Xt\X\betahat
&= \lambda s\\
\Leftrightarrow {\underbrace{\Xt \y}_{p \times 1}}
&= {\underbrace{\vphantom{ \Xt \y } \lambda s}_{p \times 1}},
&& s \in [-1,1]^{p} \\
\intertext{Das $j$-te Element entspricht}
\xt_{j}\y
&= \lambda s_j,
&& s_j \in [-1,1] \Leftrightarrow \lambda s_j \in [-\lambda, \lambda] \\
\Leftrightarrow |\xt_{j}\y|
&\leq \lambda,
&& \forall j \in \{1,\dots,p\}
\end{align*}
\end{document}
A few points to note.
latin1
is not “for Windows”. Use it if the file is encoded in Latin-1, but you should switch to UTF-8 as soon as possible.- The options
bibtotocnumbered
andliststotoc
are deprecated. \underbrace{<code>}_{<code>}
should be braced in order to keep the correct spacing, so{\underbrace{<code>}_{<code>}}
.- Never use
...
in the input, but\dots
or, if needed, one among\dotsc
,\dotsb
or\dotsm
(see Difference of the \dots*).
You need alignat*
:
\documentclass[a4paper, abstracton, bibtotocnumbered,liststotoc,12pt]{scrartcl}
%%%%% Betriebssystemabhängige Eingabedekodierung
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc} %% für Windows
\usepackage[ngerman]{babel}
\usepackage{amsthm}
\usepackage{mathtools}
\newcommand{\matr}[1]{\mathbf{#1}}
\newcommand{\X}{\matr{X}} %Matrix von X
\newcommand{\y}{\matr{y}} %y als voller Vektor
\newcommand{\Xt}{\X^\mathbf{T}} %Matrix von X
\newcommand{\x}{\matr{x}}%Regressor von X
\newcommand{\xt}{\x^\mathbf{T}}%Regressor von X
\newcommand{\betahat}{\hat{\beta}} %betahat
\begin{document}
\begin{alignat*}{2}
\Xt\y-\Xt\X\betahat &= \lambda s && \\
\Leftrightarrow \underbrace{\Xt \y}_{p \times 1} &= \underbrace{\vphantom{\Xt\y}\lambda s}_{p\times1}, &&\quad s \in [-1,1]^{p} \\
\intertext{\textnormal{Das $j$-te Element entspricht}}
\xt_{j}\y &= \lambda s_j, &&\quad s_j \in [-1,1] \Leftrightarrow \lambda s_j \in [-\lambda, \lambda] \\
\Leftrightarrow |\xt_{j}\y| &\leq \lambda, &&\quad \forall j \in \{1,...,p\}
\end{alignat*}
\end{document}