# How to write conditional expression in LaTeX with text and math [duplicate]

Being new in LaTeX I don't know where to look for the proper resources. I know this is probably documented for easily somewhere out there, but I'm struggling with knowing where to look - any help isappreciated.

How would you reproduce in LaTeX this conditional expression with one curly brace on the left side?

• Hi @Iver, as a new user I recommend you reading some tips on how to ask a good question. There is more probability that you receive good answers and that your post will be useful for future users. Also try adding a mwe to your question. – GiuTeX Apr 28 at 11:21
• @GiuTeX Thanks, will do! – Iver Finne Apr 28 at 11:22
• You are welcome, and welcome also to the community. – GiuTeX Apr 28 at 11:39

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$t(v) = \begin{cases} \text{John} & \text{hvis v er variabelen x}\\ \text{Paul} & \text{hvis v er variabelen y}\\ \text{George} & \text{hvis v er variabelen z}\\ \text{Yoko} & \text{ellers} \end{cases}$
\end{document}


Jendrik notes in the comments that the cases* environment, available with mathtools, sets the right-hand alignment automatically as text, rather than math, which is useful in this situation. Thus, the cases* equivalent of the above code would be

\documentclass{article}
\usepackage{mathtools}
\begin{document}
$t(v) = \begin{cases*} \text{John} & hvis v er variabelen x\\ \text{Paul} & hvis v er variabelen y\\ \text{George} & hvis v er variabelen z\\ \text{Yoko} & ellers \end{cases*}$
\end{document}


Here's an alternative with tabstackengine, allowing the content to be set in text mode directly:

\documentclass{article}
\usepackage{tabstackengine}
\begin{document}
$\setstackgap{L}{1.1\normalbaselineskip}% ROW BASELINESKIP \setstacktabbedgap{1em}% INTER-COLUMN GAP t(v) = \left\{ \tabbedCenterstack[l]{% LEFT ALIGNED STACK CONTENT John & hvis v er variabelen x\\ Paul & hvis v er variabelen y\\ George & hvis v er variabelen z\\ Yoko & ellers } \right.$
\end{document}

• Wonderful! Thank you! – Iver Finne Apr 28 at 11:34
• I’d suggest using mathtools instead of amsmath (which is then loaded internally by mathtools), and then use cases* instead of cases. In this way, one doesn’t need to use\text{} in the second column. – Jendrik Stelzner Apr 28 at 22:30
• @JendrikStelzner Thanks for the tip. I have added it to the answer. – Steven B. Segletes Apr 28 at 22:56

Another solution with just array and bigdelim:

\documentclass{article}
\usepackage{bigdelim, array}

\begin{document}

\begin{center}
\sffamily
\ldelim\{{4}{*}[$t(v)={}$]
& John & hvis $v$ er variabelen $x$ \\
& Paul & hvis $v$ er variabelen $y$ \\
& George & hvis $v$ er variabelen $z$ \\
& Yoko & ellers
\end{tabular}
\end{center}

\end{document}


Steven has already said enough, but just for completeness and for proving that LaTeX offers always new roads I'll post another solution by means of .., though I think cases environment is the most appropriate for this job.

\documentclass{article}

\usepackage{amsmath}

\begin{document}
$t(v) = \left\{\begin{array}{lr} \text{John} & \text{hvis v er variabelen x}\\ \text{Paul} & \text{hvis v er variabelen y}\\ \text{George} & \text{hvis v er variabelen z}\\ \text{Yoko} & \text{ellers} \end{array}\right.$
\end{document}


This produces

Notice that amsmath package is only needed for text command. A benefit from using array would be that you can control alignment by means of r and l (respectively right aligned, and left aligned) arguments in \begin{array}{lr}, and you can add lines as well as control manually spacing, by writing

$t(v) = \left\{\begin{array}{l@{\hspace{3em}}|r} \text{John} & \text{hvis v er variabelen x}\\ \hline \text{Paul} & \text{hvis v er variabelen y}\\ \text{George} & \text{hvis v er variabelen z}\\ \text{Yoko} & \text{ellers} \end{array}\right.$


@{\hspace{3em}} can be set to whichever value in em, cm, pt and other measure you like for making custom space between columns, while | can be used for adding vertical lines bewreen the arry columns. Finally adding \hline you can achieve horizontal rules.

Little addendum: \left\{ and \right. fake the case behaviour of cases environment, so that if you prefer you can switch it to othe parenthesis, as [, (, \langle and so on.