5

I am trying to modify LaTeX's brackets (\cases) to make something like the one on the left:

click here

I could only find code for square box and brackets (\cases), but not for this particular variant on any forums. The problem is how to either how to add a "tip" on [ or straighten up the corners on \cases. Could anyone help me with this?

Thanks.

  • You can upload png files. Without the picture, it is hard to find out what you want. – marmot Jun 29 '18 at 3:01
  • 1
    Perhaps take a look at this advanced answer? – Ruixi Zhang Jun 29 '18 at 3:37
6

DISCLAIMER: This is almost entirely taken from Steven B. Segletes answer and what I made here is also more a matrix that can be abused for cases. But the upshot is that with Steven's code one can draw any bracket one wants after very simple adjustments. Of course, some basic knowledge of TikZ helps.

\documentclass{article} % https://tex.stackexchange.com/a/327584/121799
\usepackage{tikz,amsmath,environ}
\usetikzlibrary{decorations.pathreplacing,calc}
\tikzset{
    ncbar angle/.initial=90,
    ncbar/.style={
        to path=(\tikztostart)
        -- ($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)
        -- ($(\tikztotarget)!($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztostart)$)
        -- (\tikztotarget)
    },
    ncbar/.default=0.5cm,
    freaky dim/.default=4pt,
    freaky/.style={
        to path={let \p1=(\tikztostart),\p2=(\tikztotarget) in (\tikztostart)
        -- ($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)
        -- ({\x1-#1},{(\y1+\y2)/2-abs(#1)})
        -- ({\x1-2*#1},{(\y1+\y2)/2})
        -- ({\x1-#1},{(\y1+\y2)/2+abs(#1)})
        -- ($(\tikztotarget)!($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztostart)$)
        -- (\tikztotarget)}
    },
    freaky/.default=0.5cm,
}

\tikzset{freaky left brace/.style={freaky=0.5ex}}
\tikzset{freaky right brace/.style={freaky=-0.5ex}}

\tikzset{square left brace/.style={ncbar=0.5ex}}
\tikzset{square right brace/.style={ncbar=-0.5ex}}

\tikzset{round left paren/.style={ncbar=0.3cm,out=115,in=-115}}
\tikzset{round right paren/.style={ncbar=0.3cm,out=65,in=-65}}
%

\NewEnviron{flcases}{\setbox0=\hbox{$\,\begin{matrix}\BODY\end{matrix}\,$}%
  \setbox2=\hbox{\begin{tikzpicture}
    \draw [thick] (0,\botdim) to [freaky left brace] (0,\topdim);
    \copy0
  \end{tikzpicture}}
  \vcenter{\hbox{\copy2}}%
}


\def\topdim{\the\dimexpr+\ht0+.5\ht\strutbox-.5\dp\strutbox-3pt\relax}
\def\botdim{\the\dimexpr-\ht0+.5\ht\strutbox-.5\dp\strutbox+3pt\relax}
\begin{document}

\[ f(x)=
\begin{flcases}
   0 & \text{if}~x<0  \\ 
   \pi & \text{if}~x\ge0  
\end{flcases}%
\]

\end{document}

enter image description here

  • Wow, thanks. Segletes's code (you referred to ) works like charm. I'm still trying to comprehend his code and tweak it for my own use though. – user37891 Jun 29 '18 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.