Conditional linebreak in align environment
It is better and simpler to use the mechanisms provided by etoolbox
, where you can set up a toggle
(or alternatively a bool
). The following makes your example work, but I don't like the coding and will give another approach below:
\documentclass{article}
\usepackage{amsmath,etoolbox}
\newtoggle{smallformat}
\settoggle{smallformat}{false} %set to true or false as required
\iftoggle{smallformat}{\setlength{\textwidth}{5cm}}{}
\begin{document}
\begin{align}
A
&\leq
\sum_{i = 0}^L \|(I-K^i)(I-F^i)u\|_{V(\Omega)} \nonumber \\
%
&\leq
\sum_{i = 0}^L \left(\|(B - C^i)(I - D^i)u\|_{V(\Omega)}
\iftoggle{smallformat}{\right. \nonumber\\}{}
%
\label{eq:One}
\iftoggle{smallformat}{&\quad\ }{}
+
\iftoggle{smallformat}{\left. }{}
\|(I - D^i)(I - S^i) u \|_{V(\Omega)} \right).
\end{align}
\end{document}
The addition to your code declares a new toggle smallformat
, and in this case initially sets it to false
. You then have the \iftoggle{smallformat}{truecase}{falsecase}
for use in your code.
Now to how I would prefer to code this:
\documentclass{article}
\usepackage{mathtools,amssymb,etoolbox}
\newtoggle{smallformat}
\settoggle{smallformat}{true}
\iftoggle{smallformat}{\setlength{\textwidth}{5cm}}{}
\newcommand{\eqbreak}[1][2]{\\&\hskip#1em}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\begin{document}
\begin{equation}
\label{eq:One}
\begin{split}
A &\leqslant
\sum_{i = 0}^L \norm{(I-K^i)(I-F^i)u}_{V(\Omega)} \\
&\leqslant
\sum_{i = 0}^L \bigl(\norm{B - C^i)(I - D^i)u}_{V(\Omega)}
\iftoggle{smallformat}{\eqbreak}{}
+ \|(I - D^i)(I - S^i) u \|_{V(\Omega)} \bigr).
\end{split}
\end{equation}
\end{document}
Your display is a single equation spread over several lines, therefore equation
with an internal split
is more appropriate as you only want one equation number.
Use of \left...\right
should be restricted as much as possible. Using \bigl...\bigr
and their cousins makes coding in your example easier. It also avoids the situation where all the tall material is on just one line, which in the narrow version would result in parentheses of different sizes.
The optional line break is via a new command \eqbreak
that I find very useful in displays. It takes an optional argument saying how much the next line should be indented. By default this is set to \qquad
= 2em
, but e.g. \eqbreak[4]
will give twice as much.
I have used mathtools
to set up a \norm
command form your \|...\|
, this should give better spacing around these terms, without something like this LaTeX does not which \|
is a left delimiter.
Finally I prefer \leqslant
to \leq
.
Narrow output:
You need to not insert {}
around the alignment markup in the small case, and you need to not put &
in the middle of the \if
in the other case, so..
\documentclass{article}
\usepackage{amsmath}
\newcommand{\usesmallformat}{1}
\setlength{\textwidth}{5cm}
\makeatletter
\newcommand\sformat{%
\relax\ifdefined\usesmallformat\expandafter\@firstofone\else\expandafter\@gobble\fi}
\makeatother
\begin{document}
\begin{align}
A
&\leq
\sum_{i = 0}^L \|(I-K^i)(I-F^i)u\|_{V(\Omega)} \nonumber \\
%
&\leq
\sum_{i = 0}^L \left(\|(B - C^i)(I - D^i)u\|_{V(\Omega)}
\sformat{\right. \nonumber\\}
%
\label{eq:One}
\sformat{&\quad\ }
+
\sformat{\left.}
\|(I - D^i)(I - S^i) u \|_{V(\Omega)} \right).
\end{align}
\end{document}