# Side by side equation not fitting in page

I want to write an equation that has two equivalent forms so i want to write them both side by side. So I do this using the following

  \begin{aligned} (X',Y',Z')=\begin{cases} \left(X,2Y,\dfrac{Z}{2}\right), & \mbox{if } ~0\leq X<\dfrac{1}{2}, ~0\leq Y<\dfrac{1}{2} \\ \left(2X,2Y-1,\dfrac{Z}{2}+\dfrac{1}{2}\right), & \mbox{if } ~0\leq X<\dfrac{1}{2}, ~\dfrac{1}{2}\leq Y<1\\ \left(X-1,2Y,\dfrac{Z}{2}+\dfrac{1}{4}\right), & \mbox{if } ~\dfrac{1}{2}\leq X<1, ~0\leq Y<\dfrac{1}{2}\\ \left(2X-1,2Y-1,\dfrac{Z}{2}+\dfrac{3}{4}\right), & \mbox{if } ~\dfrac{1}{2}\leq X<1, ~\dfrac{1}{2}\leq Y<1\\ \end{cases} \end{aligned} \implies \begin{aligned} X'=\begin{cases} \text{mod}(2X,N), & \mbox{if }~Z+1\equiv (3\vee 1)\text{mod}~4\\ \text{mod}(2X,N)+1, & \mbox{if }~Z+1\equiv (2\vee 0)\text{mod}4\\ \end{cases}\\ Y'=\begin{cases} \text{mod}(2Y,N), & \mbox{if }~Z+1\equiv (2\vee 1)\text{mod}4\\ \text{mod}(2Y,N)+1, & \mbox{if }~Z+1\equiv (3\vee 0)\text{mod}4\\ \end{cases}\\ Z'=\begin{cases} \bigg\lfloor\dfrac{Z}{4}\bigg\rfloor,~~~~~~~~~~~~~,& \mbox{if}~0\leq X<\dfrac{N}{2}-1~\text{and}~ 0\leq Y<\dfrac{N}{2}-1 \\ \bigg\lfloor\dfrac{Z}{4}\bigg\rfloor+\dfrac{2N}{4},& \mbox{if}~0\leq X<\dfrac{N}{2}-1~\text{and}~\dfrac{N}{2}-1<Y \\ \bigg\lfloor\dfrac{Z}{4}\bigg\rfloor+\dfrac{N}{4}, & \mbox{if}~\dfrac{N}{2}+1<X~\text{and}~ 0\leq Y<\dfrac{N}{2}-1 \\ \bigg\lfloor\dfrac{Z}{4}\bigg\rfloor+\dfrac{3N}{4},& \mbox{if}~\dfrac{N}{2}-1<X~\text{and}~ \dfrac{N}{2}-1<Y \\ \end{cases} \end{aligned}


it is giving the output

but this as you can see is not aligned properly, it is not fitting in the page, what should be the solution? Can anybody fix this?

• given that it is clearly going to be very large why force over-sized fractions with \dfrac rather than \frac ? also aligned (eg the first one at least) with a single row, and no & alignment point does nothing useful. – David Carlisle May 19 at 15:34
• Please fix the example so that people can run it to see the problem and test answers. In particular you have given no indication of the page size so impossible to suggest how to make this fit. – David Carlisle May 19 at 15:35
• even if you fix the bad markup (\dfrac, ~, \text{max}, \bigg then at \tiny font size it is still too wide for a default article page width, and it is unreadably small. I do not think it is feasible to get this on one line and be understandable. – David Carlisle May 19 at 15:59

I see no way to get these two big blocks side by side. Why not just one above the other?

\documentclass{article}
\usepackage{amsmath,mathtools}

\usepackage{showframe}

\DeclareMathOperator{\omod}{mod}

\begin{document}

\begingroup
\setlength{\multlinegap}{0pt}
\begin{multline*}
(X',Y',Z')=
\begin{dcases}
\left(X,2Y,\frac{Z}{2}\right),
& \text{if } 0\leq X<\frac{1}{2},\ 0\leq Y<\frac{1}{2} \\
\left(2X,2Y-1,\frac{Z}{2}+\frac{1}{2}\right),
& \text{if } 0\leq X<\frac{1}{2},\ \frac{1}{2}\leq Y<1 \\
\left(X-1,2Y,\frac{Z}{2}+\frac{1}{4}\right),
& \text{if } \frac{1}{2}\leq X<1,\ 0\leq Y<\frac{1}{2} \\
\left(2X-1,2Y-1,\frac{Z}{2}+\frac{3}{4}\right),
& \text{if } \frac{1}{2}\leq X<1,\ \frac{1}{2}\leq Y<1\\
\end{dcases}
\\
\implies\left\{
\begin{aligned}
X'&=
\begin{dcases}
\omod(2X,N),   & \text{if } Z+1\equiv (3\vee 1)\pmod{4}\\
\omod(2X,N)+1, & \text{if } Z+1\equiv (2\vee 0)\pmod{4}\\
\end{dcases}
\\
Y'&=
\begin{dcases}
\omod(2Y,N),   & \text{if } Z+1\equiv (2\vee 1)\pmod{4}\\
\omod(2Y,N)+1, & \text{if } Z+1\equiv (3\vee 0)\pmod{4}\\
\end{dcases}
\\
Z'&=
\begin{dcases}
\biggl\lfloor\frac{Z}{4}\biggr\rfloor,
& \text{if } 0\leq X<\frac{N}{2}-1 \text{ and } 0\leq Y<\frac{N}{2}-1  \\
\biggl\lfloor\frac{Z}{4}\biggr\rfloor+\frac{2N}{4},
& \text{if } 0\leq X<\frac{N}{2}-1 \text{ and } \frac{N}{2}-1<Y  \\
\biggl\lfloor\frac{Z}{4}\biggr\rfloor+\frac{N}{4},
& \text{if } \frac{N}{2}+1<X \text{ and }  0\leq Y<\frac{N}{2}-1  \\
\biggl\lfloor\frac{Z}{4}\biggr\rfloor+\frac{3N}{4},
& \text{if } \frac{N}{2}-1<X \text{ and }  \frac{N}{2}-1<Y \\
\end{dcases}
\end{aligned}
\right.
\end{multline*}
\endgroup

\end{document}


I locally set \multlinegap to zero in order to use up all available space. Adding a brace clarifies the meaning, in my opinion.

Note that \usepackage{showframe} has been used just to show the margins of the text block, remove it for your production version.

I made also a few changes.

1. For the mod operator I defined a suitable command (\text{mod} is wrong)
2. For the mod denoting the modulo of a congruence, use \pmod
3. \bigg\lfloor and \bigg\rfloor should be \biggl\lfloor and \biggr\rfloor
4. All ~ have disappeared
5. Instead of using \dfrac throughout, better using dcases that also takes care of the vertical spacing

Since it's not feasible to fit your equation onto a single line in portrait orientation and have it be readable, I recommend landscape orientation. I give an example with output below. To fix the alignment, just add an & before the X',Y',Z' on the right hand side of the equation.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{pdflscape}
\usepackage{geometry}

\begin{document}
\newgeometry{margin=1cm}
\begin{landscape}
\begin{aligned} (X',Y',Z')=\begin{cases} \left(X,2Y,\dfrac{Z}{2}\right), & \mbox{if } ~0\leq X<\dfrac{1}{2}, ~0\leq Y<\dfrac{1}{2} \\ \left(2X,2Y-1,\dfrac{Z}{2}+\dfrac{1}{2}\right), & \mbox{if } ~0\leq X<\dfrac{1}{2}, ~\dfrac{1}{2}\leq Y<1\\ \left(X-1,2Y,\dfrac{Z}{2}+\dfrac{1}{4}\right), & \mbox{if } ~\dfrac{1}{2}\leq X<1, ~0\leq Y<\dfrac{1}{2}\\ \left(2X-1,2Y-1,\dfrac{Z}{2}+\dfrac{3}{4}\right), & \mbox{if } ~\dfrac{1}{2}\leq X<1, ~\dfrac{1}{2}\leq Y<1\\ \end{cases} \end{aligned} \hspace{.5cm} \implies \hspace{.5cm} \begin{aligned} & X'=\begin{cases} \text{mod}(2X,N), & \mbox{if }~Z+1\equiv (3\vee 1)\text{mod}~4\\ \text{mod}(2X,N)+1, & \mbox{if }~Z+1\equiv (2\vee 0)\text{mod}4\\ \end{cases}\\ & Y'=\begin{cases} \text{mod}(2Y,N), & \mbox{if }~Z+1\equiv (2\vee 1)\text{mod}4\\ \text{mod}(2Y,N)+1, & \mbox{if }~Z+1\equiv (3\vee 0)\text{mod}4\\ \end{cases}\\ & Z'=\begin{cases} \bigg\lfloor\dfrac{Z}{4}\bigg\rfloor,~~~~~~~~~~~~~,& \mbox{if}~0\leq X<\dfrac{N}{2}-1~\text{and}~ 0\leq Y<\dfrac{N}{2}-1 \\ \bigg\lfloor\dfrac{Z}{4}\bigg\rfloor+\dfrac{2N}{4},& \mbox{if}~0\leq X<\dfrac{N}{2}-1~\text{and}~\dfrac{N}{2}-1<Y \\ \bigg\lfloor\dfrac{Z}{4}\bigg\rfloor+\dfrac{N}{4}, & \mbox{if}~\dfrac{N}{2}+1<X~\text{and}~ 0\leq Y<\dfrac{N}{2}-1 \\ \bigg\lfloor\dfrac{Z}{4}\bigg\rfloor+\dfrac{3N}{4},& \mbox{if}~\dfrac{N}{2}-1<X~\text{and}~ \dfrac{N}{2}-1<Y \\ \end{cases} \end{aligned}
\end{landscape}
\restoregeometry
\end{document}



• In the OP as well as in the answers so far, the commas seem to be misplaced in the cases clauses: each comma surely should follow the condition, rather than separating the value from the condition. – murray May 24 at 14:24

Here is a solution that doesn't use cases and converts to interval notation. Note that the X' = ..., Y' = ... and Z' = ... almost aligns perfectly with (X',Y',Z')

\documentclass{article}
\usepackage{amsmath}
\usepackage{showframe}

\newcommand{\range}[3]{\ensuremath{#1 \in \left[#2, ~#3\right)}}% Interval notation [...)
\newcommand{\infRange}[2]{\ensuremath{#1 \in \left(-\infty, ~#2\right)}}% Interval notation (...)
\newcommand{\MOD}[2]{\ensuremath{\text{mod}(#1, #2)}}
\newcommand{\tuple}[3]{\ensuremath{\left(#1, #2, #3\right)\hspace*{-0.75ex},}}% (a, b, c)
\newcommand{\floor}[2]{\ensuremath{\bigg\lfloor\dfrac{#1}{#2}\bigg\rfloor}}% floor(a/b)
\begin{document}
{\def\arraystretch{2}
\begin{align*}
(X',Y',Z')=\left\{
\begin{array}{*{15}{l}}
\tuple{X}   {2Y}    {\dfrac{Z}{2}}              & \text{if } \range{X}{0}{\dfrac{1}{2}} \text{and } \range{Y}{0}{\dfrac{1}{2}}\\
\tuple{2X}  {2Y-1}  {\dfrac{Z}{2}+\dfrac{1}{2}} & \text{if } \range{X}{0}{\dfrac{1}{2}} \text{and } \range{Y}{\dfrac{1}{2}}{1}\\
\tuple{X}   {2Y}    {\dfrac{Z}{2}+\dfrac{1}{4}} & \text{if } \range{X}{\dfrac{1}{2}}{1} \text{and } \range{Y}{0}{\dfrac{1}{2}}\\
\tuple{2X-1}{2Y-1}  {\dfrac{Z}{2}+\dfrac{3}{4}} & \text{if } \range{X}{\dfrac{1}{2}}{1} \text{and } \range{Y}{\dfrac{1}{2}}{1}\\
\end{array}\right.\hspace*{-1.6pt}
%,%if you want a comma afterwards
\end{align*}
\begin{align*}
\implies
\left\{
\begin{aligned}
X' &= \left\{\begin{array}{*{3}{l}}
\MOD{2X}{N}    & \text{if } & Z+1 \equiv (3 \vee 1) (\text{mod }4)\\
\MOD{2X}{N}+1  & \text{if } & Z+1 \equiv (2 \vee 0) (\text{mod }4)\\
\end{array}\right.\\
Y' &= \left\{\begin{array}{*{3}{l}}
\MOD{2Y}{N}    & \text{if } & Z+1 \equiv (2\vee 1) (\text{mod }4)\\
\MOD{2Y}{N}+1  & \text{if } & Z+1 \equiv (3 \vee 0) (\text{mod }4)\\
\end{array}\right.\\
Z' &= \left\{\begin{array}{*{3}{l}}
\floor{Z}{4}                & \text{if } &\range{X}{0}{\dfrac{N}{2}-1} \text{and } \range{Y}{0}{\dfrac{N}{2}-1}\\
\floor{Z}{4}+\dfrac{2N}{4}  & \text{if } &\range{X}{0}{\dfrac{N}{2}-1} \text{and } \infRange{\dfrac{N}{2}-1}{Y}\\
\floor{Z}{4}+\dfrac{N}{4}   & \text{if } &\infRange{\dfrac{N}{2}+1}{X} \text{and } \range{Y}{0}{\dfrac{N}{2}-1}\\
\floor{Z}{4}+\dfrac{3N}{4}  & \text{if } &\infRange{\dfrac{N}{2}-1}{X} \text{and } \infRange{\dfrac{N}{2}-1}{Y}\\
\end{array}\right.\hspace*{-1.2pt}
\end{aligned}
\right.
\end{align*}
}
\end{document}