# How to add the length of the figure?

I type in different equations and would be glad to know, if one can add a variable length in the line. This is my minimal code:

\documentclass{article}
\usepackage{amsfonts, amsmath}
\begin{document}
\begin{itemize}
\item $\forall a,b,c, \in \mathbb{R} : \qquad a \le b \Rightarrow a+c \le b + c$
\item $\forall a,b,c, \in \mathbb{R} : \qquad a \le b \Rightarrow \begin{cases} a \cdot c \le b \cdot c \ \text{falls} \ c \ge 0 \\ a \cdot c \ge b \cdot c \ \text{falls} \ c \le 0 \end{cases}$
\end{itemize}
\end{document}


that results in

Now I would like to tell LaTeX:

"LaTeX, as I want the lines be nicely aligned horizontally in the list here, take the height (here: horizontal space between the left pick and the right endings) of the brace in the second item and add me the space of the same length before a+c in the first item".

So, I just want the space to follow the bracket width. Are such things possible in LaTeX?

• I'm not sure I understand. Do you want to add horizontal space between \Rightarrow and a+c, equivalent to the width of the brace? – Torbjørn T. Oct 22 '16 at 8:48
• You can use \vphantom{\begin{cases} ... \end{cases}} just before a+c... – Werner Oct 22 '16 at 8:57
• In this case yes, this is the horizontal width of the brace. – Kirill Oct 22 '16 at 8:59
• @Werner, I liked the idea, but am not sure that it works... I tried it. – Kirill Oct 22 '16 at 9:04
• @Kirill: Your actual question should be about horizontal alignment, not vertical. – Werner Oct 22 '16 at 14:39

\hphantom is the right track. However, the full size of an empty environment cases will not work, because it also adds space between the two columns, which are separated by \quad (this space should go before "falls"). And at the end, TeX adds the space \nulldelimiterspace of the matching \right. that closes \left\lbrace. The full definition of cases in package amsmath:

\renewenvironment{cases}{%
\matrix@check\cases\env@cases
}{%
\endarray\right.%
}
\def\env@cases{%
\let\@ifnextchar\new@ifnextchar
\left\lbrace
\def\arraystretch{1.2}%
}


The following example defines \HPhantomLeftCases to simulate the space for the left brace of the environment cases. It takes an argument, where the lines with the largest elements of the lines go to get the right size of the left brace.

Additionally, the example further vertically aligns variables a, b, and c by increasing the space for the \cdot to take the horizontal space of the plus sign.

BTW, the example uses \colon, which behaves as punctuation character rather than a relational operator as : does.

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

\newcommand*{\HPhantomLeftCases}[1]{%
\hphantom{%
\renewcommand*{\arraystretch}{1.2}%
\left\lbrace
\vphantom{\begin{array}{@{}l@{}}#1\end{array}}%
\right.%
\kern-\nulldelimiterspace
}%
}
\makeatletter
\newcommand*{\WideCDot}{%
\mathbin{\mathpalette\@WideCDot{}}%
}
\newcommand*{\@WideCDot}[2]{%
% #1: math style
% #2: unused
\sbox0{$#1+\m@th$}%
\hbox to \wd0{\hfil$#1\cdot\m@th$\hfil}%
}
\makeatother

\begin{document}
\begin{itemize}
\item $\forall a,b,c, \in \mathbb{R}\colon \qquad a \le b \Rightarrow \HPhantomLeftCases{a\\b} a+c \le b + c$
\item $\forall a,b,c, \in \mathbb{R}\colon \qquad a \le b \Rightarrow \begin{cases} a \WideCDot c \le b \WideCDot c & \text{falls} \ c \ge 0 \\ a \WideCDot c \ge b \WideCDot c & \text{falls} \ c \le 0 \end{cases}$
\end{itemize}
\end{document}


Of course, the vertical alignments are quite exaggerated (IMHO, I do not see a need to add the phantom space for the left cases brace). But, the example shows, how it can be done, and gives a choice.

• Thank you, @Heiko Oberdiek, that is a really nice one! Vertically alignment looks awesome, true! I will work throough your answer. Thank you. – Kirill Nov 14 '16 at 21:59

Looks like \hphantom{\Bigg\{} might do the trick.

\documentclass{article}
\usepackage{amsfonts, amsmath}
\begin{document}
\begin{itemize}
\item $\forall a,b,c, \in \mathbb{R} : \qquad a \le b \Rightarrow \hphantom{\Bigg\{} a+c \le b + c$
\item $\forall a,b,c, \in \mathbb{R} : \qquad a \le b \Rightarrow \begin{cases} a \cdot c \le b \cdot c \ \text{falls} \ c \ge 0 \\ a \cdot c \ge b \cdot c \ \text{falls} \ c \le 0 \end{cases}$
\end{itemize}
\end{document}

• Yes, it really nicely does! Thank you for this particular issue. But can I programm the space? There is surely a specificator in the LaTeX code that says: "curly brackets have the width/height x". In this particular question it was necessary to insert a space equal to the brace. We've entered the brace. But can we tell Latex to enter the length n of some figure somewhere as n, 2n, 3/4n \sin{\pi^2} and so on? Thanks again! – Kirill Oct 22 '16 at 9:51
• @Kirill Braces can have different width depending on their size. – egreg Oct 22 '16 at 14:40
• @egreg, I propose. But still, "Latex, draw the brace and store it length x in the buffer. By the next compilation add me the space of the width x in a particular place." should be possible. As we can use expressions like "[width=0.3\textlength]" for figures, expressions like e.g. \hspace{2\braceheight} or \ruleheight=2\textheights should exists. These are all boxes still. – Kirill Oct 23 '16 at 6:23

You decide if you really need this.

I define a cases+ environment that behaves like cases, but stores the width of the brace in the aux file for processing in the next LaTeX run.

Each cases+ environment must have a label that is used in the corresponding \phantombrace command.

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{eqparbox}
\usepackage{environ}

\makeatletter
\NewEnviron{cases+}[1]{%
\sbox\z@{% measure the cases without the brace
\def\lbrace{.\kern-\nulldelimiterspace}%
$\begin{cases}\BODY\end{cases}$%
}%
\sbox\tw@{$\begin{cases}\BODY\end{cases}$}%
\protected@write\@auxout{}{\string\caseswidthstore{#1}{\the\dimexpr\wd\tw@-\wd\z@}}%
\begin{cases}\BODY\end{cases}
}
\newcommand{\caseswidthstore}[2]{%
\expandafter\xdef\csname cws@@#1\endcsname{#2}%
}
\newcommand{\phantombrace}[1]{%
\kern\@ifundefined{cws@@#1}{0pt}{\@nameuse{cws@@#1}}\relax
}
\makeatother

\begin{document}

Two line \texttt{cases}
\begin{itemize}
\item $\forall a,b,c, \in \mathbb{R} : \qquad a \le b \Rightarrow \phantombrace{foo2} a+c \le b + c$
\item $\forall a,b,c, \in \mathbb{R} : \qquad a \le b \Rightarrow \begin{cases+}{foo2} a \cdot c \le b \cdot c \ \text{falls} \ c \ge 0 \\ a \cdot c \ge b \cdot c \ \text{falls} \ c \le 0 \end{cases+}$
\end{itemize}

Five line \texttt{cases}
\begin{itemize}
\item $\forall a,b,c, \in \mathbb{R} : \qquad a \le b \Rightarrow \phantombrace{foo5} a+c \le b + c$
\item $\forall a,b,c, \in \mathbb{R} : \qquad a \le b \Rightarrow \begin{cases+}{foo5} a \cdot c \le b \cdot c \ \text{falls} \ c \ge 0 \\ a \cdot c \le b \cdot c \ \text{falls} \ c \ge 0 \\ a \cdot c \le b \cdot c \ \text{falls} \ c \ge 0 \\ a \cdot c \le b \cdot c \ \text{falls} \ c \ge 0 \\ a \cdot c \ge b \cdot c \ \text{falls} \ c \le 0 \end{cases+}$
\end{itemize}

\end{document}


The code in the .aux file reads

\caseswidthstore{foo2}{8.05559pt}
\caseswidthstore{foo5}{8.8889pt}


so you see that indeed the two braces have different widths.