# How to write two functions horizontally?

If I want to write two functions f and g vertically in the center of the page I will write like this:

\begin{align*} \f(x)=\left\{\begin{array}{lll}                 1 & \textnormal{if} & x\in A \\                 2 & \textnormal{} & \textnormal{otherwise}             \end{array}\right. \end{align*}  \begin{align*} \g(x)=\left\{\begin{array}{lll}                 1 & \textnormal{if} & x\in B \\                 2 & \textnormal{} & \textnormal{otherwise}             \end{array}\right. \end{align*} 


How I write this two functions horizontally, one in the left end another one in the right end ?

Replay

As egreg pointed out, since you are not have any alignment points for the align environment, you could simply use gather* (or equation* since you are converting to a one line equation):

## Notes:

• You should also have a look at the cases (and dcases if using mathtools package).
• There should never be two subsequent display math equations without some text in between, and you should not leave a blank line (a commented line is fine) between display math environments. Otherwise there is too much vertical space.
• You can use \text{} as well to get to upright roman text in math mode (with amsmath).

## Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}

% Not sure what these are defined as so adjust as desired
\newcommand*{\f}{F}%
\newcommand*{\g}{G}%

\begin{document}
\begin{gather*}
\f(x)=\left\{\begin{array}{lll}
1 & \textnormal{if} & x\in A \\
2 & \textnormal{} & \textnormal{otherwise}
\end{array}\right.
\g(x)=\left\{\begin{array}{lll}
1 & \textnormal{if} & x\in B \\
2 & \textnormal{} & \textnormal{otherwise}
\end{array}\right.
\end{gather*}
\end{document}



If you have multiple lines of equations and do require horizontal alignment points, then this can also be done with the align environment.

## Notes:

• The align environment provides multiple rl pairs of equations with spaces between them.
• The alignat environment provides multiple rl pairs without spaces so spaces would need to be inserted if so desired.

## Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}

% Not sure what these are defined as so adjust as desired
\newcommand*{\f}{F}%
\newcommand*{\g}{G}%

\begin{document}
\begin{align*}
\f(x)=\left\{\begin{array}{lll}
1 & \textnormal{if} & x\in A \\
2 & \textnormal{} & \textnormal{otherwise}
\end{array}\right. &&
\g(x)=\left\{\begin{array}{lll}
1 & \textnormal{if} & x\in B \\
2 & \textnormal{} & \textnormal{otherwise}
\end{array}\right.
\end{align*}
\end{document}



Since the others have been faster and posted the solutions with align and alignat, I will post the one with minipages (as suggested by Peter Grill). :)

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\begin{document}

%with minipages

\begin{minipage}{.45\linewidth}
$f(x) = \begin{cases} 1 & \textnormal{if x\in A} \\ 2 & \textnormal{otherwise} \end{cases}$
\end{minipage}
\begin{minipage}{.45\linewidth}
$g(x) = \begin{cases} 1 & \text{if x\in B} \\ 2 & \textnormal{otherwise} \end{cases}$
\end{minipage}
\end{document}



I slightly modified your code (it does not compile - see \f and \g...) and also used cases instead of array.

If "horizontally" in this case means side by side, you can use the alignat* environment from »amsmath« (here loaded by »mathtools« from the »mh« bundle).

\documentclass[11pt]{article}

\begin{document}
\begin{alignat*}{2}
f(x)&=\left\{
\begin{array}{lll}
1 & \textnormal{if} & x\in A \\
2 & \textnormal{} & \textnormal{otherwise}
\end{array}
\right.
g(x)&=\left\{
\begin{array}{lll}
1 & \textnormal{if} & x\in B \\
2 & \textnormal{} & \textnormal{otherwise}
\end{array}
\right.
\end{alignat*}
\end{document}


Category: horizontal alignment Time: 2012-06-09 Views: 0