How to align the conditions in a hierarchical structure?
Here's a solution that uses the multirow
package and its eponymous command \multirow
:
\documentclass{article}
\usepackage{amsmath,multirow}
\begin{document}
\noindent
Original code:
\begin{equation*}
\text{Start}
\left\{\begin{aligned} \text{Do A,} \quad \quad\quad \quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\text{if a happens} \\
\text{otherwise} \left\{\begin{aligned} \text{Try B,}
\quad \quad \quad \quad \quad \quad \quad\quad\quad \text{if b occurs}\\
\text{Try C} \left\{\begin{aligned} \text{Perform C1} \quad \quad \text{if
c increases}\\
\text{Perform C2, } \quad \text{if c decreases}
\end{aligned} \right.
\end{aligned} \right.
\end{aligned} \right.
\end{equation*}
\bigskip\noindent
New code:
\begin{equation*}
\text{Start}
\left\{ \begin{array}{ll}
\text{Do A} & \text{if a happens}\\
\multirow{3}{*}{$ % restart math mode
\text{otherwise}
\left\{ \begin{array}{l}
\text{Try B}\\
\text{Try C}
\left\{ \begin{array}{l}
\text{Perform C1}\\
\text{Perform C2}
\end{array} \right.
\end{array} \right. %
$} % end of scope of multirow
& \text{if b occurs } \\
& \text{if c increases} \\
& \text{if c decreases}
\end{array} \right.
\end{equation*}
\end{document}
Remark: This solution is similar in structure (and, in particular, the use of nested array
s) to the one provided in @Werner's answer to an earlier question, except that the multirow
package is used to here to typeset correctly the otherwise
string (and the subsequent material)
Addendum: The OP has asked how one would exchange the order of the TryB/TryC items. To do so, exchange the order of the two rows in the middle of three array
structures and (ii) rearrange the order of the "if b occurs"/"if c increases"/"if c decreases" strings.
\documentclass{article}
\usepackage{amsmath,multirow}
\begin{document}
\begin{equation*}
\text{Start}
\left\{ \begin{array}{ll}
\text{Do A} & \text{if a happens}\\
\multirow{3}{*}{$ % restart math mode
\text{otherwise}
\left\{ \begin{array}{l}
\text{Try C}
\left\{ \begin{array}{l}
\text{Perform C1}\\
\text{Perform C2}
\end{array} \right. \\
\text{Try B}
\end{array} \right. %
$} % end of scope of multirow
& \text{if c increases} \\
& \text{if c decreases} \\
& \text{if b occurs}
\end{array} \right.
\end{equation*}
\end{document}
You can change the interline spacing by resetting the length \LSG
, currently set to 1.4\baselineskip
. The rest just stacking, and scaling the braces to the stack height.
\documentclass{article}
\usepackage[usestackEOL]{stackengine}[2013-10-15]
\usepackage{scalerel}
\newcommand\rbsa[2]{\raisebox{#1}{\scaleleftright[2ex]{\{}{#2}{.}}}
\def\stacktype{L}
\def\stackalignment{l}
\newlength{\LSG}
\setlength{\LSG}{1.4\baselineskip}
\setstackgap{L}{\LSG}
\begin{document}
\savestack{\cstack}{\rbsa{.5\LSG}{\stackunder{Perform C1}{Perform C2,}}}
\savestack{\bcstack}{\rbsa{\LSG}{\stackunder[1.5\LSG]{Try B,}{Try C\cstack}}}
\savestack{\abcstack}{\rbsa{1.5\LSG}{\stackunder[2\LSG]{Do A}{otherwise\bcstack}}}
Start\abcstack~~~~~~\Centerstack[l]
{if a happens\\if b occurs\\if c increases\\if c decreases}
\end{document}
To get the alternate format, referenced by the OP:
\documentclass{article}
\usepackage[usestackEOL]{stackengine}[2013-10-15]
\usepackage{scalerel}
\newcommand\rbsa[2]{\raisebox{#1}{\scaleleftright[2ex]{\{}{#2}{.}}}
\def\stacktype{L}
\def\stackalignment{l}
\newlength{\LSG}
\setlength{\LSG}{1.4\baselineskip}
\setstackgap{L}{\LSG}
\begin{document}
\savestack{\cstack}{\rbsa{.5\LSG}{\stackunder{Perform C1}{Perform C2,}}}
\savestack{\bcstack}{\rbsa{0.5\LSG}{\stackunder[1.5\LSG]{Try C\cstack}{Try B,}}}
\savestack{\abcstack}{\rbsa{1.5\LSG}{\stackunder[2\LSG]{Do A}{otherwise\bcstack}}}
Start\abcstack~~~~~~\Centerstack[l]
{if a happens\\if c increases\\if c decreases\\if b occurs}
\end{document}
I find the given structure a little difficult to follow: some of the if conditions are much to far from the actions they govern. Also, it seems that there ought to be another "otherwise" just before "Try C". I would reorganize the whole thing:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\text{Start}
\ \begin{cases} \text{if a happens}& \text{Do A,} \\
\text{otherwise}&
\begin{cases}\text{if b occurs}& \text{Try B,}\\
\text{otherwise}& \text{Try C}
\ \begin{cases}\text{if c increases}& \text{Perform C1,}\\
\text{if c decreases}& \text{Perform C2.}
\end{cases}
\end{cases}
\end{cases}
\end{equation*}
\end{document}