7

Is there a way to get curly braces with tikz which look more like this one? curly brace

At the moment I'm using the following to get curly braces:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\usetikzlibrary{decorations.pathreplacing}

\draw[decorate,decoration={brace,amplitude=0.75cm}]  (0,0) -- (1,0);  
\draw[decorate,decoration={brace]  (0,0) -- (1,0);

\end{tikzpicture}
\end{document}

But that results in:

output curly braces

The point is that I need short curly braces with kind of a high amplitude which still look like braces.

5

Here is a primitive meta-decoration, but it is not as general as the standard brace such as raise,mirror etc. won't work. However, the brace amplitude and other local brace options are passed and would be available as I tried to show below. The new raise amount is controlled with meta-amplitude key.

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.pathreplacing}

\pgfdeclaremetadecoration{raisedbrace}{initial}{%
\state{initial}[width=\pgfmetadecoratedpathlength]{%
  \decoration{brace}%
  \pgfsetdecorationsegmenttransformation{%
      \pgftransformyshift{\pgfmetadecorationsegmentamplitude}%
  }
  \beforedecoration{
    \pgfpathmoveto{\pgfpointmetadecoratedpathfirst}
    \pgfpathlineto{\pgfpointadd{%
      \pgfpointmetadecoratedpathfirst%
      }{%
      \pgfpointpolar{\pgfdecoratedangle+90}{\pgfmetadecorationsegmentamplitude}%
      }%
    }%
  }%
  \afterdecoration{%
    \pgfpathlineto{\pgfpointmetadecoratedpathlast}%
    \pgfusepath{stroke}
  }
}
}
\begin{document}
\begin{tikzpicture}
\draw[style=help lines] (-1,-1) grid[step=1cm] (3,3);
\draw[decorate,decoration={raisedbrace,amplitude=2mm,meta-amplitude=4mm}]  (0,1) -- (2,2);  
\draw[decorate,decoration={raisedbrace,amplitude=4mm,meta-amplitude=1cm}]  (0,-1) -- (2,-0.5);
\draw[decorate,decoration={raisedbrace,amplitude=1cm,meta-amplitude=5mm}]  (2,3) -- (2,-0.5);
\end{tikzpicture}
\end{document}

enter image description here

  • Thank you very much. I can emulate the "raise" option by adjusting the nodes (like \draw... ([yshift=1cm]node.east)...), but how to change the thickness? Do you have another suggestion? – antonius Aug 10 '14 at 15:05
  • 1
    @antonius Just put \pgfsetlinewidth{\pgflinewidth} before \pgfusepath{stroke} then you can put thick etc. inside \draw options and it should obey. – percusse Aug 10 '14 at 15:54
2

This should help you:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}[scale=1]
\draw [decorate,decoration={brace,amplitude=10pt},xshift=-4pt,yshift=0pt]
(0.5,0.5) -- (5.0,0.5) node [black,midway,xshift=-0.6cm]
{};
\node at (2.65,1.0) {text};
\end{tikzpicture}
\end{document} 

The length of the brace can be altered with the values in the \draw command (0.5,0.5) -- (5.0,0.5). Similarly the text position need to be altered. enter image description here

Update

Varying the amplitude, we get something like this:
enter image description here

Code

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}[scale=1]
\draw [decorate,decoration={brace,amplitude=14pt},xshift=-4pt,yshift=0pt]
(0.5,0.5) -- (5.0,0.5) node [black,midway,xshift=-0.6cm]
{};
\node at (2.65,1.2) {text};
\end{tikzpicture}
\end{document} 
  • Thanks but for short curly braces it will result in the same mutation as above (e.g. "(0.5,0.5) -- (1.5,0.5)" ) – antonius Aug 6 '14 at 16:52

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.