# Draw intervals with overbrace descriptions

For a report I need the following picture, which I would like to draw in LaTeX/TikZ.

The idea is that there are discrete intervals on the real line and above these intervals I want to write which elements are in them...

(For example like the picture I added. )

Is there an rather easy way to draw this with tikz?

I never have worked with tikz and so maybe you can help me to draw this...

I think I will then be able to change it for other intervalls by myself.

EDIT: I found code on the internet and modified it.

\begin{tikzpicture}[decoration=brace]
% Die Grundlinie:
\draw(0,0)--(10,0);
% Striche und Beschriftung in Abständen 0, 2, 4, 6, ...
\foreach \x/\xtext in {0/$-m-n+1$,2/$-m-1$,4/$-m$,6/$0$,8/$m$,10/$m+n-1$}
\draw(\x,5pt)--(\x,-5pt) node[below] {\xtext};
% obere geschweifte Klammer mit Text darüber:
\draw[decorate, yshift=2ex]  (0,0) -- node[above=0.4ex] {$0$'s}  (2,0);
\draw[decorate, yshift=2ex]  (10,0) -- node[above=0.4ex] {$l$'s and $0$'s with $l$'s separated by at least two $0$'s}  (4,0);
\end{tikzpicture}

What I get is:

Why is the second bracket the other way round?

• you could use \path (0,0) coordinate (a) (1,0) coordinate (b) to establish your intervals bounds, \draw (a) edge[|-|] (b) to draw the intervals, \node[anchor=south] at (a) {$-m-n+1$}; for the labels and \draw[decoration=brace] (a) -- (b) for the braces Apr 19, 2015 at 10:26
• Okay, pls see my edit. Apr 19, 2015 at 10:42
• it goes in the wrong direction because the path is constructed from right to left. If you swap the coordinates of the path you get it right Apr 19, 2015 at 10:44
• You can swap coordinates as Bordaigorl suggested or add decoration=mirror in drawing options. Apr 19, 2015 at 11:04

The braces, from decorations.pathreplacing library, have an option mirror, which reverses the face direction of the brace. So, that is all you should add to get it in the right direction. You can do it like this:

\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}

\begin{tikzpicture}
% Die Grundlinie:
\draw(0,0)--(10,0);
% Striche und Beschriftung in Abständen 0, 2, 4, 6, ...
\foreach \x/\xtext in {0/$-m-n+1$,2/$-m-1$,4/$-m$,6/$0$,8/$m$,10/$m+n-1$}
\draw(\x,5pt)--(\x,-5pt) node[below] {\xtext};
% obere geschweifte Klammer mit Text darüber:
\draw[decorate, decoration={brace}, yshift=2ex]  (0,0) -- node[above=0.4ex] {$0$'s}  (2,0);
\draw[decorate, decoration={brace, mirror}, yshift=2ex]  (10,0) -- node[above=0.4ex] {$l$'s and $0$'s with $l$'s separated by at least two $0$'s}  (4,0);
\end{tikzpicture}

\end{document}

• hehe, i think thats exactly the code i found in internet, too and edited :D Apr 19, 2015 at 11:11
• @math12 So, why is it working if it is the same as yours? Apr 19, 2015 at 11:21
• Is there any way to replace braces by square brackets? May 12, 2018 at 15:11

Here is a pstricks solution:

\documentclass[a4paper, pdf, x11names]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{stackengine}
\setstackEOL{\\}

\begin{document}

\centering
\psset{braceWidthOuter=4pt, braceWidthInner=4pt, braceWidth=0.8pt, labelsep =2ex}
\begin{pspicture}
\psset{linecolor =IndianRed3}
\psline(-1.2,0)(13.2,0)
\psdots[dotstyle=B|](0,0.02)(3,0.02)(4.2,0.02)(12,0.02)
\pnodes(0,0.6ex){Z1}(3,0.6ex){Z2}(4.2,0.6ex){L1}(12,0.6ex){L2}
\uput[d](Z1){$-m-n + 1$}\uput[d](Z2){$-m-1$\uput[d](L1){$-m$}}\uput[d](L2){$m + n - 1$}
\psset{rot=-90,linecolor=SlateGray4}
\psbrace*(Z2)(Z1){\makebox[0pt]{only $0$’ s}}
\psbrace*(L2)(L1){\makebox[0pt]{\Centerstack{$0$’s and $l$’s\\$l$’s separated by at least $2$ $0$’s}}}
\end{pspicture}

\end{document}