Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Essentially the same question as Draw Curly Braces in TikZ except that I want the brace to wrap around a circle to display an angular sector (for example 0-30 degrees). How can I do this?


I dont know if it is even possible, but here is a MWE

\documentclass[12pt]{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.4]
\draw[style=thick] (0,0) circle (7);
\draw[thin,dashed] (0, 0 ) -- (100:7) ;
\draw[thin,dashed] (0, 0 ) -- (170:7) ;
\end{tikzpicture}
\end{document}
share|improve this question
3  
What have you tried so far? What is and what is not working? –  Psirus Feb 16 '12 at 7:56

4 Answers 4

up vote 23 down vote accepted

Here's a first version, the meeting point in the middle lokks still bad, but I'm working on it.

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usepackage{ifthen}

\newcommand{\cucubr}[7]{%
%origin point, circle radius, start angle, end angle, distance c-b, brace radius, brace options
\pgfmathsetmacro{\helpangleedge}{atan(#6/(#2+#5+#6))}%
\pgfmathsetmacro{\helpanglemid}{atan(#6/(#2+#5+2*#6))}%
\pgfmathsetmacro{\halfangle}{(#4-#3)/2+#3}%
\pgfmathsetmacro{\innerradius}{#2+#5}%
\pgfmathsetmacro{\midradius}{#2+#5+#6}%
\pgfmathsetmacro{\outerradius}{#2+#5+2*#6}%
\pgfmathsetmacro{\firstmidanglestart}{mod(\halfangle-\helpanglemid+180,360)}%
\pgfmathsetmacro{\secondmidanglestart}{mod(\halfangle+\helpanglemid+180,360)}%
\pgfmathsetmacro{\firstmidanglestop}{mod(\halfangle-\helpanglemid+180,360)-90}%
\pgfmathsetmacro{\secondmidanglestop}{mod(\halfangle+\helpanglemid+180,360)+90}%
%
\draw[#7] (#1) ++ (#3:\innerradius) arc (#3+270:#3+360:#6) arc (#3+\helpangleedge:\halfangle-\helpanglemid:\midradius) arc (\firstmidanglestart:\firstmidanglestop:#6);%
\draw[#7] (#1) ++ (#4:\innerradius) arc (#4+90:#4:#6) arc (#4-\helpangleedge:\halfangle+\helpanglemid:\midradius) arc (\secondmidanglestart:\secondmidanglestop:#6);% node[black, text width=2.5cm,draw] {mid:\firstmidanglestart, one:\firstmidanglestop, two:\secondmidanglestop, half:\halfangle};%
}

\begin{document}

\begin{tikzpicture}
\draw (0,0) -- (0:4) arc (0:90:4) -- cycle;
\draw (0,0) -- (90:4) arc (90:180:4) -- cycle;
\draw (0,0) -- (180:4) arc (180:270:4) -- cycle;
\draw (0,0) -- (270:4) arc (270:360:4) -- cycle;
\cucubr{0,0}{4}{0}{90}{0.4}{0.5}{thick,red}
\cucubr{0,0}{4}{90}{180}{0.9}{1.0}{thick,green}
\cucubr{0,0}{4}{180}{270}{0.2}{0.3}{thick,blue}
\cucubr{0,0}{4}{270}{360}{0.6}{0.6}{thick,teal}
\end{tikzpicture}

\end{document}

enter image description here


Edit 1: I got a much better variant than before, it involves more math now. While this should be correct, I still got variations, so the brace would't always close in the middle. I think my math is correct, and I ran into some computation deviations in TikZ: the angles computed by TikZ vary by up to 0.35 degrees from the real. While this does does not seem much, it was up to 10% of the angle, or the equivalent of 1.5 linewidths. As I found no way around, I decided to start drawing from the center. That way the brace ends meet in the middle, and I only needed to adapt one value due to deviations. Here's the final code:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}

\newcommand{\cucubr}[7]{%
%origin point, circle radius, start angle, end angle, distance c-b, brace radius, brace options
\pgfmathsetmacro{\helpangleedge}{acos(1-pow(#6,2)/2/pow(#2+#5,2))}%
\pgfmathsetmacro{\turnangleedge}{90+(\helpangleedge/2)}%
\pgfmathsetmacro{\helpanglemid}{acos(1-pow(#6,2)/2/pow(#2+#5+2*#6,2))}%
\pgfmathsetmacro{\turnanglemid}{90-(\helpanglemid/2)}%
\pgfmathsetmacro{\halfangle}{(#4-#3)/2+#3}%
\pgfmathsetmacro{\midradius}{#2+#5+#6}%
\pgfmathsetmacro{\outerradius}{#2+#5+1.88*#6}%
\pgfmathsetmacro{\firstmidanglestart}{mod(\halfangle-\helpanglemid+180,360)}%
\pgfmathsetmacro{\secondmidanglestart}{mod(\halfangle+\helpanglemid+180,360)}%
\pgfmathsetmacro{\firstmidanglestop}{mod(\halfangle-\helpanglemid/2+180,360)-\turnanglemid}%
\pgfmathsetmacro{\secondmidanglestop}{mod(\halfangle+\helpanglemid/2+180,360)++\turnanglemid}%
%
\draw[#7] (#1) ++ (\halfangle:\outerradius) arc (\firstmidanglestop:\firstmidanglestart:#6) arc (\halfangle-\helpanglemid:#3+\helpangleedge:\midradius) arc (#3+270+\turnangleedge+\helpangleedge/2:#3+270+\helpangleedge/2:#6) ;%
%
\draw[#7] (#1) ++ (\halfangle:\outerradius) arc (\secondmidanglestop:\secondmidanglestart:#6) arc (\halfangle+\helpanglemid:#4-\helpangleedge:\midradius) arc (#4+90-\turnangleedge-\helpangleedge/2:#4+90-\helpangleedge/2:#6);%
}

\begin{document}

\begin{tikzpicture}
\draw (0,0) -- (00:4) arc (0:90:4) -- cycle;
\draw (0,0) -- (90:4) arc (90:180:4) -- cycle;
\draw (0,0) -- (180:4) arc (180:270:4) -- cycle;
\draw (0,0) -- (270:4) arc (270:360:4) -- cycle;
\cucubr{0,0}{4}{0}{90}{0.4}{0.5}{red,densely dotted}
\cucubr{0,0}{4}{90}{180}{0.9}{1.0}{thin,green}
\cucubr{0,0}{4}{180}{270}{0.2}{0.3}{ultra thick,blue,densely dashed}
\cucubr{0,0}{4}{270}{360}{0.6}{0.6}{thick,teal,-latex}
\end{tikzpicture}

\end{document}

enter image description here


Edit 2: I double and tripple checked the math, it really, really should be correct. So I started investigating the deviations when calculating. The TikZ manual states that the power and accuracy of it's engine are limited due to limitations of TeX. Sadly, this is the first time I ran into them. I calculated the values of the angles I needed for different values of circle radius and brace radius:

enter image description here

The values should decrease left to right and top down, but for small radii they don't. As this limits the accuracy achievable, I decided to choose yet another approach: starting the brace from inside and outside, and then connecting the pieces via to[out=<degrees>,in=<degrees>]. This looks well enough, at least if you don't choose a lage brace radius for a small circle radius.

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\pgfkeys{/tikz/savenumber/.code 2 args={\global\edef#1{#2}}}

\newcommand{\cucubr}[7]{%
%origin point, circle radius, start angle, end angle, distance c-b, brace radius, brace options
\pgfmathsetmacro{\helpangleedge}{acos(1-pow(#6,2)/2/pow(#2+#5,2))}%
\pgfmathsetmacro{\turnangleedge}{90+(\helpangleedge/2)}%
\pgfmathsetmacro{\helpanglemid}{acos(1-pow(#6,2)/2/pow(#2+#5+2*#6,2))}%
\pgfmathsetmacro{\turnanglemid}{90-(\helpanglemid/2)}%
\pgfmathsetmacro{\halfangle}{(#4-#3)/2+#3}%
\pgfmathsetmacro{\innerradius}{#2+#5}%
\pgfmathsetmacro{\midradius}{#2+#5+#6}%
\pgfmathsetmacro{\outerradius}{#2+#5+2*#6-sqrt(1/#2)*0.01}%
\pgfmathsetmacro{\firstmidanglestart}{mod(\halfangle-\helpanglemid+180,360)}%
\pgfmathsetmacro{\secondmidanglestart}{mod(\halfangle+\helpanglemid+180,360)}%
\pgfmathsetmacro{\firstmidanglestop}{mod(\halfangle-\helpanglemid/2+180,360)-\turnanglemid}%
\pgfmathsetmacro{\secondmidanglestop}{mod(\halfangle+\helpanglemid/2+180,360)+\turnanglemid}%
%
\draw[#7] (#1) ++ (\halfangle:\outerradius) arc (\firstmidanglestop:\firstmidanglestart:#6) node (A) {};%
\draw[#7] (#1) ++ (#3:\innerradius) arc (#3+270+\helpangleedge/2:#3+270+\turnangleedge+\helpangleedge/2:#6) node (B) {};%
%
\draw[#7] (#1) ++ (\halfangle:\outerradius) arc (\secondmidanglestop:\secondmidanglestart:#6) node (C) {};%
\draw[#7] (#1) ++ (#4:\innerradius) arc (#4+90-\helpangleedge/2:#4+90-\turnangleedge-\helpangleedge/2:#6) node (D) {};%
%
\draw[#7] (A.center) to[out=\firstmidanglestop+180,in=#3+90+\helpangleedge/2] (B.center);%
\draw[#7] (C.center) to[out=\secondmidanglestop-180,in=#4-90-\helpangleedge/2](D.center);%
}

\begin{document}

\begin{tikzpicture}
\draw[very thin,gray,densely dotted] (0,0) -- (20:7);
\draw[very thin,gray,densely dotted] (0,0) -- (80:7);
\draw[very thin,gray,densely dotted] (0,0) -- (150:7);
\foreach \r in {1,...,6}
{   \cucubr{0,0}{\r}{20}{80}{0.2}{0.3}{blue}
    \cucubr{0,0}{\r}{80}{150}{0.5}{0.5}{red}
}
\end{tikzpicture}

\end{document}

enter image description here

As you can see, the smaller braces look "staircasey", but this vanishes with higher ratios of circle radius to brace radius.

enter image description here

share|improve this answer
    
Very good effort. I write no it's impossible now I look stupid. The way you take was a possibility but I thought this way was too difficult and too complicated for something simple and flexible. –  Alain Matthes Feb 16 '12 at 12:59
    
You don't look too stupid :) This solution only works exact if r<<R. As one can see at the teal and green braces, for larger brace radii the overlap is not good anymore. I will do some math and try to improve it. –  Tom Bombadil Feb 16 '12 at 15:15
    
Fine result ! I try \foreach \r in {1,2,3,4,5,6} {\cucubr{0,0}{\r}{20}{80}{0.2}{0.3}{blue} \cucubr{0,0}{\r}{80}{150}{0.2}{0.3}{red}}. The result is not very good with little radius. I don't have enough time to look at my next suggestion but perhaps it's possible to adapt some code with the radius of arc or perhaps to fix some dimensions. –  Alain Matthes Feb 18 '12 at 10:53
    
Thanks for the remark, robbed me of the whole day ;) Sadly it is due to limited accuracy. So you might be right after all, it is not solvable exactly, but at least something like "close enough". –  Tom Bombadil Feb 18 '12 at 19:04

Finally I get the next code without "big" calculus.

Update version 2

I added some keys like tip angle and find something better for the tip.

Figure

main

Details

detail

Code

\documentclass[11pt]{scrartcl}
\usepackage{tikz}

\makeatletter 

\tikzset{curlybrace/.style={rounded corners=2pt,line cap=round}}%  
\pgfkeys{%
/curlybrace/.cd,%
tip angle/.code     =  \def\cb@angle{#1},
/curlybrace/.unknown/.code ={\let\searchname=\pgfkeyscurrentname
                              \pgfkeysalso{\searchname/.try=#1,
                              /tikz/\searchname/.retry=#1}}}  
\def\curlybrace{\pgfutil@ifnextchar[{\curly@brace}{\curly@brace[]}}%

\def\curly@brace[#1]#2#3#4{% 
\pgfkeys{/curlybrace/.cd,
tip angle = 0.75}% 
\pgfqkeys{/curlybrace}{#1}% 
\ifnum 1>#4 \def\cbrd{0.05} \else \def\cbrd{0.075} \fi
\draw[/curlybrace/.cd,curlybrace,#1]  (#2:#4-\cbrd) -- (#2:#4) arc (#2:{(#2+#3)/2-\cb@angle}:#4) --({(#2+#3)/2}:#4+\cbrd) coordinate (curlybracetipn);
\draw[/curlybrace/.cd,curlybrace,#1] ({(#2+#3)/2}:#4+\cbrd) -- ({(#2+#3)/2+\cb@angle}:#4) arc ({(#2+#3)/2+\cb@angle} :#3:#4) --(#3:#4-\cbrd);
}

\begin{document}
\begin{tikzpicture}[scale=1.5]
\draw[help lines](-3,-3) grid (3,3);
\curlybrace[color=blue,thick]{30}{60}{1.2}
\curlybrace[color=blue]{30}{60}{0.6}
\curlybrace[color=blue]{30}{60}{2}    
\draw circle(1cm);

\curlybrace[color=red]{90}{160}{3} \node[red,anchor=south] at (curlybracetipn) {$70^\circ$};
\curlybrace[color=red,thin]{90}{160}{1.2}
\curlybrace[color=red,thin]{90}{160}{0.6}
\curlybrace[color=red,thin]{90}{160}{0.3} 
\curlybrace[color=red,thin]{90}{160}{2} 
\curlybrace[color=red]{90}{160}{3} 
\curlybrace[color=green!40!black,thick]{180}{360}{1.2}
\curlybrace[color=green!40!black,thick]{180}{360}{0.6}
\curlybrace[color=green!40!black,thick]{180}{360}{0.3} 
\curlybrace[color=green!40!black,ultra thick,tip angle=2]{180}{360}{3}   
\end{tikzpicture}
\end{document} 

Todo

It's possible to add :

  1. a coordinate to place a label at the middle of the brace (do)
  2. some keys with pgfkeys to get a better control for rounded corners, for the little angle that I use at the middle of the brace (0.75 degree). We can calc this angle function of the radius.(do)
  3. expression to calc some values according to the radius like \def\cbrd{0.05}we can avoid this with some calculus.
  4. styles with pgfkeys to add arrows for example. it's easy (do)
  5. to get a better junction at the middle, it would be interesting to use only one path . Actually the result is fine with line width not to big.(do with line cap=round)

First idea

It was to begin with a simple code to get some coordinates and then to add some ornaments but finally "rounded corners" was enough.

\documentclass[11pt]{scrartcl}
\usepackage{tikz}

\newcommand{\curlybrace}[3]{%
\draw  (#1:#3-0.1) -- (#1:#3) arc (#1:#2:#3)--(#2:#3-0.1) ; 
\draw ({(#1+#2)/2}:#3) -- ({(#1+#2)/2}:#3+0.1);}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[help lines](-3,-3) grid (3,3);
\curlybrace{30}{60}{1.2}
\curlybrace{30}{60}{2}    
\draw circle(1cm);

\curlybrace{90}{160}{1.2}
\curlybrace{90}{160}{2}  
\end{tikzpicture} 
\end{document} 

enter image description here

share|improve this answer
    
It's also possible to scale the curly braces. –  Alain Matthes Feb 20 '12 at 12:39
    
The best answer! –  In PSTricks we trust Feb 20 '12 at 14:19
    
Wow, very nice approach! Good to see your ego couldn't let it go ;) Definitively deserves to be the accepted answer. –  Tom Bombadil Feb 21 '12 at 10:35
    
@TomBombadil I did not want to continue to remain stupid ! :) The accepted answer is for you because you gave the first effort and I tried to find a solution because you show me the way. I did not like the idea of curly brace, it's why I started slowly. –  Alain Matthes Feb 21 '12 at 11:09

This is the PMB (poor man's brace) version.

It uses the arrow styles right to reserved and left to reserved from the arrow library.

The solution isn't very sophisticated as it enables one only to draw braces around (0,0). (The shift key is already used, so an outer scope is necessary here.)

Next step would be to include this in some kind of style of to or arc which I won't follow up because we already have Alain Matthes's solution.

Code

\documentclass[
    tikz,
    border=2pt,
]{standalone}
\usetikzlibrary{arrows}
\newcommand*{\braceme}[6][]{% #1 = optional
                            % #2 = radius
                            % #3 = start angle
                            % #4 = end angle
                            % #5 = node name
                            % #6 = node content
\draw[
    shift={(#3:#2)},
    right to reversed-right to reversed,
    shorten >=-.75\pgflinewidth,
    #1
    ] (0,0)
        arc[radius=#2, start angle=#3, end angle=#3+(#4-#3)/2] node[rotate=#3+(#4-#3)/2-90,above=2pt] (#5) {#6};
\draw[
    shift={({#3+(#4-#3)/2}:#2)},
    left to reversed-left to reversed,
    shorten <=-.75\pgflinewidth,
    #1
    ] (0,0)
        arc[radius=#2, start angle=#3+(#4-#3)/2, end angle=#4];
}
\begin{document}
\begin{tikzpicture}[scale=0.4]
\draw[style=thick] (0,0) circle (7);
\draw[thin,dashed] (0, 0 ) -- (100:7) ;
\draw[thin,dashed] (0, 0 ) -- (170:7) ;
\braceme[thick]{7.5}{100}{170}{br1}{Hi!}
\braceme[thick]{8}{180}{390}{br2}{Test?}
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer

Is this what you had in mind?

\documentclass{article}

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

\begin{document}
\begin{tikzpicture}
  \draw (0,0) circle (1);
  \draw (0,0) -- (1,0);
  \draw (0,0) -- (30:1);
  \draw [decorate,decoration={brace,amplitude=2pt,mirror,raise=4pt}] (1,0) -- (30:1);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks, though this wasnt what I had in mind. A lienar brace wont neatly cover for example, 60 degrees. –  yayu Feb 16 '12 at 8:06
    
I think the answer is no with tikz. Why not use a classic method with an arc ? –  Alain Matthes Feb 16 '12 at 8:46
    
@Altermundus -- if you really want to, you can always remove a comment that you've written. if you mouse over your comment, there's a little "x" at the end that you can click on to do the job. (speaking from lots of practice.) –  barbara beeton Feb 16 '12 at 13:36
    
@barbarabeeton I think it's impossible to transform a linear brace to a curved(curly) brace (with tikz). But I need to keep my comment to know why I'm stupid _ Tikz can draw every vector object with obstinacy, talent and work_. Tom makes a great effort to get a fine result. Perhaps it's possible to improve a little bit the code. –  Alain Matthes Feb 18 '12 at 10:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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