4

How can I make underline brace for part of formula y+z in a tikzpicture below? I am aware of underbrace in math mode, but I want the brace be outside of a revblock.

\begin{tikzpicture}
[revblock/.style={shape=rectangle,draw=blue!50,fill=blue!30,
                  minimum height=3mm, minimum width=100mm,
                  text width=99mm}]
\matrix [column sep=2mm,row sep=2mm,ampersand replacement=\&]
{
\node(rev3name){$\rho_3$:}; \& \node(rev3)[revblock]{$x = y + z$};\\
};
\end{tikzpicture}

enter image description here

Moriambar
  • 11,466
ashim
  • 1,783

3 Answers3

5

It can be achieved with the decorations library:

Code

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

\begin{document}

\begin{tikzpicture}
[revblock/.style={shape=rectangle,draw=blue!50,fill=blue!30,
                  minimum height=3mm, minimum width=100mm,
                  text width=99mm}]
\matrix [column sep=2mm,row sep=2mm,ampersand replacement=\&]
{
\node(rev3name){$\rho_3$:}; \& \node(rev3)[revblock]{$x = y + z$};\\    };
\draw[decoration={brace,amplitude=2mm,mirror,raise=1mm},decorate] (rev3.south west) -- (rev3.south east);
\end{tikzpicture}

\end{document}

Output

enter image description here


Edit 1: Regarding your comment, you can use the positioning library:

Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc,positioning}

\begin{document}

\begin{tikzpicture}
[revblock/.style={shape=rectangle,draw=blue!50,fill=blue!30,
                  minimum height=3mm, minimum width=100mm,
                  text width=99mm}]
\matrix [column sep=2mm,row sep=2mm,ampersand replacement=\&]
{
\node(rev3name){$\rho_3$:}; \& \node(rev3)[revblock]{$x = y + z$};\\   };
\draw[decoration={brace,amplitude=2mm,mirror,raise=1mm},decorate] (rev3.south west) -- (rev3.south east);
\node[below=5mm of rev3,draw] (textnode) {Here's some text.};
\end{tikzpicture}

\end{document}

Output

enter image description here

Ignasi
  • 136,588
Tom Bombadil
  • 40,123
  • You don't actually need calc, since there is a syntax to "raise" the brace (which is where you use calc), for instance: decoration={brace,raise=2pt}. – Lay May 06 '13 at 06:25
  • @Lay: Nice, I didn't know that. Makes it somewhat easier! – Tom Bombadil May 06 '13 at 06:28
  • @Tom Bombadil Great answer, but how can I make text which is pointed by the brace. I can create a node and specify exact position but if I change it the text then it would be headache to move all picture – ashim May 06 '13 at 06:29
  • It's quite easy with the positioning library. – Tom Bombadil May 06 '13 at 06:36
  • You can avoid the mirror option if you give the path from east to west – Alain Matthes May 06 '13 at 06:36
  • thanks! the last remark. I actually asked about how to point exactly on y+z part, but not all purple box. Any idea? – ashim May 06 '13 at 06:38
  • You can avoid positioning and some code with \draw[decorate] (rev3.south east) -- node [draw,below=7mm] {TEXT}(rev3.south west); – Alain Matthes May 06 '13 at 06:52
3

Something more general if you want to place another brace with a part of the equation. I think you can use the tikzmark library but it's easy to do.

I made some changes with the initial code : no minimum width but align=left

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

  \begin{document}

  \begin{tikzpicture}
  [remember picture,
  revblock/.style={shape=rectangle,draw=blue!50,fill=blue!30,
                    minimum height=3mm, text width=100mm,align=left },
                  decoration={brace,amplitude=3mm,raise=10pt,mirror}]

  \matrix [column sep=2mm,row sep=2mm,ampersand replacement=\&]
  {\node(rev3name){$\rho_3$:};     \&    \node(rev3)[revblock]{$x=
        \tikz[remember picture] \coordinate (a); 
          y+z \tikz[remember picture] \coordinate (b);
          $};   \\
  };
  \draw[decorate] (rev3.south west) --  node [draw,below=7mm] {TEXT}
                                        (rev3.south east);      
   \begin{scope}[ decoration={brace,amplitude=1mm,raise=6pt,mirror}] 
  \draw[decorate,red] (a.south west) -- node[below=6pt] {right part}
                                        (b.south east);
    \end{scope}
   \end{tikzpicture}
  \end{document}

enter image description here

Moriambar
  • 11,466
Alain Matthes
  • 95,075
2

You have to use decorations. Specifying a brace decoration and then drawing a line segment will instead draw a brace "pointing to the right". Here, drawing that brace starting from the bottom-right of the box and going toward the bottom-left will produce the desired result (as far as I understand the question):

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

\begin{document}

\begin{tikzpicture}
[revblock/.style={shape=rectangle,draw=blue!50,fill=blue!30,
                  minimum height=3mm, minimum width=100mm,
                  text width=99mm}]
\matrix [column sep=2mm,row sep=2mm,ampersand replacement=\&]
{
\node(rev3name){$\rho_3$:}; \& \node(rev3)[revblock]{$x = y + z$};\\
};
\draw[decorate,decoration={brace,raise=2pt}] (rev3.south east) -- (rev3.south west);
\end{tikzpicture}

\end{document}
Moriambar
  • 11,466
Lay
  • 343