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.

I have this code to draw a mass on a spring and now I want to have a curly brace below the spring to denote the distance: x_0. How do I do this?

\begin{tikzpicture}
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.3,minimum height=0.6]

\node (wall1) [ground, minimum height=2cm] {};
\draw (wall1.north east) -- (wall1.south east);
\node [draw,minimum width=0.5cm,minimum height=0.5cm] (mass) at (2,0) {m};
\node (fix) at (0,0) {};
\draw [snake=coil,segment amplitude=5pt,segment length=5pt] (fix) -- (mass); 
\end{tikzpicture}
share|improve this question
2  
This question should help (see Andrew's TikZ answer): tex.stackexchange.com/questions/1559/… –  Seamus Aug 12 '11 at 11:24
1  
If it is a TikZ node you could use below delimiter=\{ as shown in Correct delimiter height in TikZ (see both the question source code and my answer). –  Martin Scharrer Aug 12 '11 at 11:53
add comment

1 Answer

up vote 15 down vote accepted

As suggested in Andrew's answer that Seamus linked to, you can use a brace decoration for this. If it's on the wrong side of your path, use the mirror option (or reverse the path order). To increase the spacing, you can use raise=<length>:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{patterns,snakes}

\begin{document}
\begin{tikzpicture}
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.3,minimum height=0.6]

\node (wall1) [ground, minimum height=2cm] {};
\draw (wall1.north east) -- (wall1.south east);
\node [draw,minimum width=0.5cm,minimum height=0.5cm] (mass) at (2,0) {m};
\node (fix) at (0,0) {};
\draw [
    snake=coil,
    segment amplitude=5pt,
    segment length=5pt
] (wall1.east) -- (mass); 
\draw [
    thick,
    decoration={
        brace,
        mirror,
        raise=0.5cm
    },
    decorate
] (wall1.east) -- (mass) 
node [pos=0.5,anchor=north,yshift=-0.55cm] {coil}; 
\end{tikzpicture}
\end{document}
share|improve this answer
3  
Note from the next year (2012-09-07): the snake library is now deprecated. For the code above, \usetikzlibrary{patterns,snakes} should be replaced by \usetikzlibrary{patterns,decorations.pathreplacing}. –  Evpok Sep 7 '12 at 21:09
add comment

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.