5

Consider the following code:

\documentclass{article}
\usepackage{tikz}
\usepackage{array}
\usepackage{mathtools}

\begin{document}

\begin{equation}
  a(y)=\left\{
  \begin{array}{@{}ll@{}}
    0 & \text{if}\ y < 1 \\
    \frac{1}{2}\biggl[ 1 + sin\left(\frac{2 \pi}{\theta}\right) \biggr]  & \text{if}\ 1\leq y < 4 \\
    1 & \text{if}\ 4 \leq y < 5 \\
 \frac{1}{2}\biggl[ 1 - sin\left(\frac{2 \pi}{\theta}\right) \biggr]  & \text{if}\ 6 \leq y < 7 \\
    0 & \text{otherwise}
  \end{array}\right.
\end{equation}

\end{document}

The output is:

enter image description here

How to achieve the following calligraphic curly brace (The following image borrowed from here) offered by TikZ package, in equation environment:

enter image description here

A similar style was implemented for a matrix in this answer. I couldn't implement it for an equation.

3
  • 2
    Wouldn't be better to use upright sin and smaller square brackets first? Dec 24, 2021 at 5:00
  • There are almost almost 10 rows. This is the simplified version of the code.
    – Aim
    Dec 24, 2021 at 5:02
  • 3
    I think @PrzemysławScherwentke was suggesting to reduce the vertical size of the square brackets (at least for the given example - can't say for your actual use case), and also to use \sin instead of sin. Dec 24, 2021 at 6:42

2 Answers 2

3

I suspect that there is an elegant solution using the nicematrix package, but I haven't the experience of that to provide it. Here's a tikz solution that wraps the array environment in a tikz node and then decorates the left-hand edge with a brace.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/627983/86}
\usepackage{tikz}
\usepackage{array}
\usepackage{mathtools}

\usetikzlibrary{tikzmark,decorations.pathreplacing,calligraphy}

\begin{document}
\begin{equation}
a(y)= \begin{tikzpicture}[baseline=(base)]
\node (array) {\(\displaystyle\begin{array}{@{}ll@{}} 0 & \text{if}\ y < 1 \\
\frac{1}{2}\biggl[ 1 + \sin\left(\frac{2 \pi}{\theta}\right) \biggr] & \text{if}\ 1\leq y < 4 \\
1 & \text{if}\ 4 \leq y < 5 \\
\frac{1}{2}\biggl[ 1 - \sin\left(\frac{2 \pi}{\theta}\right) \biggr] & \text{if}\ 6 \leq y < 7 \\
0 & \text{otherwise} \end{array}\)};
\path (array) +(0,-.5ex) coordinate (base);
\draw[decorate, decoration=calligraphic brace,ultra thick] (array.south west) -- (array.north west);
\end{tikzpicture}
\end{equation}
\end{document}

equation with calligraphic brace

Obviously, there are parameters to tweak to improve the look, such as line width and amplitude.

(Incidentally, this is exactly the use-case I was envisioning when I designed these braces.)

Here's with amplitude=3mm:

with a larger amplitude

3
  • Looking at the question you linked to, I see that Zarko uses amplitude=3mm, and I think that looks good here too. Dec 24, 2021 at 10:53
  • @ Andrew Stacey, can you please tell where to include the amplitude=3mm in the code? I don't see it.
    – Aim
    Dec 24, 2021 at 11:39
  • decoration={calligraphic brace, amplitude=3mm} Dec 24, 2021 at 15:16
4

I would focus on making the expression more compact, mainly by replacing the \frac notation with "slash" notation (aka inline fraction notation). And, since you're loading the mathtools package, you could use its cases* environment instead of a plain array environment.

Oh, and by all means, do write \sin, not sin.

enter image description here

\documentclass{article}
\usepackage{mathtools} % for 'cases*' environment

\begin{document}
\begin{equation}
  a(y)=
  \begin{cases*}
    0                                     & if $\hphantom{1\leq{}}y < 1$ \\
    \frac{1}{2}[ 1 + \sin(2\pi/\theta) ]  & if $1 \leq y < 4$ \\
    1                                     & if $4 \leq y < 5$ \\
    \frac{1}{2}[ 1 - \sin(2\pi/\theta) ]  & if $6 \leq y < 7$ \\
    0                                     & otherwise
  \end{cases*}
\end{equation}
\end{document}

Addendum to address the OP's follow-up comment: To generate a truly elegan tall curly brace, you could download and install the mtpro2 package -- note that while the full package isn't free of charge, its 'lite' subset is free -- and use its \ccases macro. The elegant curly brace can be up to 10 cm (4 inches) tall. Observe that the mtpro2 math fonts are in the Times Roman family of fonts; this may or may not be to your liking.

enter image description here

\documentclass{article}
\usepackage{amsmath}      % for '\text' macro
\usepackage{newtxtext}    % Times Roman clone text font
\usepackage[lite]{mtpro2} % for '\ccases' macro

\begin{document}
\begin{equation}
  a(y)=
  \ccases{
    0                                     & \text{ if $\phantom{1\leq{}}y < 1$} \\
    \frac{1}{2}[ 1 + \sin(2\pi/\theta) ]  & \text{ if $1 \leq y < 4$} \\
    1                                     & \text{ if $4 \leq y < 5$} \\
    \frac{1}{2}[ 1 - \sin(2\pi/\theta) ]  & \text{ if $6 \leq y < 7$} \\
    0                                     & \text{otherwise}
  }
\end{equation}
\end{document}
4
  • I think that calligraphy braces by TikZ package looks more elegant than the default LaTeX style. Furthermore, as the number of rows increases the default LaTeX style looses elegance.
    – Aim
    Dec 24, 2021 at 8:36
  • @Aim - Please see the addendum I just posted.
    – Mico
    Dec 24, 2021 at 10:35
  • 1
    @Sebastiano - Thanks for the edit!
    – Mico
    Dec 24, 2021 at 17:28
  • You are Always welcome 🏵️🤗🤗🤗🏵️
    – Sebastiano
    Dec 24, 2021 at 19:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .