Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Format Piecewise Functions in Confluence Using LaTeX

The LaTeX Math for Confluence team is back with another guide!

In this part of our series, we’ll explore piecewise functions, a common way to define functions with different expressions depending on conditions. They are widely used in mathematics, engineering, and technical documentation.

Missed the previous guides? Check out:

What is a piecewise function?

A piecewise function is a mathematical function defined by different expressions for different input values. Instead of using a single formula for all inputs, you specify separate rules for distinct intervals. For example, one rule might apply when x is greater than a certain number, while another applies when x is less than or equal to that number.

LaTeX - Piecewise Functions Example.jpg

How to write piecewise functions using LaTeX

In LaTeX, there are two main ways to write piecewise functions:

  • the cases environment: simple and quick

  • the array environment: flexible and customizable.

Using the cases LaTeX environment

The cases environment is the simplest way to create a piecewise function with a curly brace on the left.
 

f(x) = \begin{cases}
x^2 & \text{if } x \ge 0 \\
-x  & \text{if } x < 0
\end{cases}
  • & aligns the expressions with the conditions

  • \text{} allows normal text inside math mode

Output is a neatly aligned function with braces.

LaTeX - Piecewise Functions case.jpg

Use cases when you need a quick and clean look with two columns (expression + condition).

Using the array environment in LaTeX

The array environment is more flexible and gives you full control over the layout:

  • Add extra columns for explanations or annotations.

  • Build nested or multi-line structures.

  • Control alignment precisely with l (left), c (center), and r (right).

Example:
 

f(x) =
\left\{
\begin{array}{lll}
x^2 & \text{if } x \ge 0 & \text{positive numbers} \\
-x  & \text{if } x < 0 & \text{negative numbers} \\
0   & \text{otherwise}   & \text{neutral case}
\end{array}
\right.
  • \left\{ and \right. LaTeX commands ensure the brace scales properly

  • \text{} allows text labels or explanations

LaTeX - Piecewise Functions Array.jpg

Use array when you need more than two columns, complex layouts, or precise alignment. Our previous post explains the array LaTeX environment in more detail.

Tips for writing piecewise functions

  • Wrap all text in \text{} to avoid math-mode errors.

  • Use \displaystyle for fractions, sums, or integrals inside the function.

  • Apply \small or \scriptstyle to scale inline functions.

Wrapping up

Piecewise functions are a handy way to write formulas with conditions. No matter if you prefer cases for simplicity or array for full control, our LaTeX Math for Confluence app helps you keep your math neat and well-formatted. It’s securely hosted on Atlassian Cloud, so you can rely on it for clear and professional-looking documentation.

This post wraps up our mini-series on LaTeX math formatting. If you’d like us to explore other LaTeX tips, feel free to leave a comment or contact our support. We’d be glad to help!

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events