8

I would like to create "square-curly bracket" delimiters, somehow looking as in this question. I came up with the code below, which produces some good results, but has also some inconvenients. For instance we get these examples:

You can see that the fraction bar is not really centered (because of the exponent 'j'), and the formatting under the summation symbols is too big.

My question is:

How would you proceed to have nice-looking "square-curly" brackets?


MWE:

\documentclass{article}

\usepackage{tikz, mathtools, titletoc}

\DeclareRobustCommand{\fp}[1]{%
    \let\mybox\relax%
    \newsavebox\mybox%
    \sbox{\mybox}{$#1$}%
    \def\WIDTH{\the\dimexpr\wd\mybox + 6pt \relax}%
    \def\HEIGHT{\the\dimexpr\ht\mybox * 10 / 20 +  \dp\mybox * 10/20 + 2pt\relax}%
    \def\SHIFT{2pt}%
    \begin{tikzpicture}[baseline = -0.57ex]
    \draw  [line width=0.6]  (\SHIFT, \HEIGHT) -- (0, \HEIGHT) -- (0, 1.0pt) -- (-1.5pt, 0) -- (0, -1.0pt) -- (0, -\HEIGHT) -- (\SHIFT, -\HEIGHT);%
    \node[anchor = west] at (-0.01, 0) {\copy\mybox};%
    \draw  [line width=0.6]  (-\SHIFT + \WIDTH, \HEIGHT) -- (0 + \WIDTH, \HEIGHT) -- (0 + \WIDTH, 1.0pt) -- (1.5pt + \WIDTH, 0) -- (0 + \WIDTH, -1.0pt) -- (0 + \WIDTH, -\HEIGHT) -- (-\SHIFT + \WIDTH, -\HEIGHT);%
    \end{tikzpicture}%
}


\begin{document}

$\fp{x}         \qquad          \fp{ \frac{x a}{d} } = \left\{ \frac{x a}{d} \right\}    \leq \frac{1}{2}$

\[      \fp{ -x } = \fp{ \dfrac{a x}{d} } = \fp{ \frac{x}{2} }   = 
\fp{ \dfrac{- t \cdot a^j }{ R } }      =       \fp{ \dfrac{- t  a_j }{ R } }   \]

\[      \sum_{ \fp{r/m} \in S } r       =       \sum_{ \fp{ \frac{r}{m} } \in S } r.        \]

\end{document}
5

2 Answers 2

6

Here is a different approach. First we define a tikz style called sqbrace that draws the new brace between points. It has an optional argument to shift it perpendicular to its direction. For example,

\begin{tikzpicture}
\draw(0,0)--(2,1);
\draw[sqbrace=2](0,0)--(2,1);
\end{tikzpicture}

enter image description here

The 2 shifts the brace by 2 units, where a unit is the amount of overhang in the brace (set to 1.5pt.

Then we define a macro \mybrace{<contents>} that draws the braces around a node containing <contents>. The node is vcentered and contains vphantom contents to get the baseline in the right place.

enter image description here

\documentclass{article}

\usepackage{tikz, amsmath}
\usetikzlibrary{decorations.pathreplacing, calc}
\tikzset{
  sqbrace/.style={decorate, decoration={show path construction,
    lineto code={
      \path (\tikzinputsegmentfirst); \pgfgetlastxy{\xstart}{\ystart}
      \path (\tikzinputsegmentlast); \pgfgetlastxy{\xend}{\yend}
      \path ($(0,0)!1.5pt!(\ystart-\yend,\xend-\xstart)$); \pgfgetlastxy{\xperp}{\yperp}
      \path ($(0,0)!1.5pt!(\xend-\xstart, \yend-\ystart)$); \pgfgetlastxy{\xpar}{\ypar}
      \draw[line width=.5pt, shift={(#1*\xperp,#1*\yperp)}] (\xstart-\xperp,\ystart-\yperp)--(\xstart,\ystart)--
        ([shift={(-.5*\xpar,-.5*\ypar)}]$.5*(\xstart,\ystart)+.5*(\xend,\yend)$)--
        ([shift={(.866*\xperp,.866*\yperp)}]$.5*(\xstart,\ystart)+.5*(\xend,\yend)$)--
        ([shift={(.5*\xpar,.5*\ypar)}]$.5*(\xstart,\ystart)+.5*(\xend,\yend)$)--
        (\xend,\yend)--(\xend-\xperp,\yend-\yperp);
    }
  }},
  sqbrace/.default={0}
}
\newcommand{\mybrace}[1]{{}\mathbin{\vcenter{\hbox{\tikz{
  \node[inner ysep=.0pt, inner xsep=2pt](M){$#1\vphantom{\left(#1\right)}$};
  \draw[sqbrace](M.north east)--(M.south east);
  \draw[sqbrace](M.south west)--(M.north west);
}}}}{}}

\begin{document}
\[
\sum_{j=0}^N\mybrace{\dfrac{-t\cdot a^j}{R}}\qquad\sum_{\mybrace{\scriptstyle r/m}\in S}r\qquad\sum_{\mybrace{\frac{r}{m}}\in S}r
\]

\begin{tikzpicture}
\draw(0,0)--(2,1);
\draw[sqbrace=2](0,0)--(2,1);
\end{tikzpicture}
\end{document}
6

Not so elegant solution, but it works. Initially, the left and right bracket were vertically aligned to the baseline. After that they shifted up by .57ex which has been found empirically.

\documentclass{article}

\usepackage{tikz, mathtools, titletoc}

\newsavebox\mybox
\DeclareRobustCommand{\fp}[1]{%
    \text{\sbox{\mybox}{$#1$}%
    \def\WIDTH{\the\dimexpr\wd\mybox + 6pt \relax}%
    \def\HEIGHT{\the\dimexpr\ht\mybox * 10 / 20 +  \dp\mybox * 10/20 + 2pt\relax}%
    \def\SHIFT{2pt}%
    \begin{tikzpicture}[baseline={([yshift=-.57ex]current bounding box.center)}]
    \draw  [line width=0.6]  (\SHIFT, \HEIGHT) -- (0, \HEIGHT) -- (0, 1.0pt) -- (-1.5pt, 0) -- (0, -1.0pt) -- (0, -\HEIGHT) -- (\SHIFT, -\HEIGHT);%
    \end{tikzpicture}%
    \usebox{\mybox}%
    \begin{tikzpicture}[baseline={([yshift=-.57ex]current bounding box.center)}]
    \draw  [line width=0.6]  (-\SHIFT + \WIDTH, \HEIGHT) -- (0 + \WIDTH, \HEIGHT) -- (0 + \WIDTH, 1.0pt) -- (1.5pt + \WIDTH, 0) -- (0 + \WIDTH, -1.0pt) -- (0 + \WIDTH, -\HEIGHT) -- (-\SHIFT + \WIDTH, -\HEIGHT);%
    \end{tikzpicture}}%
}

\begin{document}

$\fp{x}         \qquad          \fp{ \frac{x a}{d} } = \left\{ \frac{x a}{d} \right\}    \leq \frac{1}{2}$

\[      \fp{ -x } = \fp{ \dfrac{a x}{d} } = \fp{ \frac{x}{2} }   = 
\fp{ \dfrac{- t \cdot a^j }{ R } }      =       \fp{ \dfrac{- t  a_j }{ R } }   \]

\[      \sum_{ \fp{r/m} \in S } r       =       \sum_{ \fp{ \frac{r}{m} } \in S } r.        \]

\end{document}

enter image description here

3
  • This seems quite cool, thanks a lot! There is just the \sum_{ \fp{r/m} \in S } r which still looks ugly (the symbols are too big).
    – Watson
    Feb 2, 2023 at 15:27
  • @Watson, this can be done putting all into the \text{} as user202729 suggested above. I have edited the post.
    – Andrey L.
    Feb 2, 2023 at 16:07
  • Thanks! I will accept your answer, unless someone else comes up with something else.
    – Watson
    Feb 2, 2023 at 16:30

You must log in to answer this question.

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