6

I'd like to put parentheses around a picture I'm drawing with tikz. I tried using \left( and \right but this gives me parentheses twice the height of the picture, with the picture only occupying the top half of space within the parentheses. How can I get parentheses the same size as the picture?

So far I have:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\[ \left( \begin{tikzpicture}[scale=0.2] \draw [magenta, line width =1mm] (0,-1) rectangle (4,3); \draw [magenta, line width=1mm] (4,-1) rectangle (6,-3); \end{tikzpicture} \right)
\]

\end{document}
Adina G
  • 280

2 Answers2

6

You can use baseline key

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\[ \left( \begin{tikzpicture}[scale=0.2,baseline=-1mm] 
\draw [magenta, line width=1mm] (0,-1) rectangle (4,3); 
\draw [magenta, line width=1mm] (4,-1) rectangle (6,-3); 
\end{tikzpicture} \right)
\]

\end{document}

enter image description here

Salim Bou
  • 17,021
  • 2
  • 31
  • 76
  • 2
    Better yet, baseline=-\the\fontdimen22\textfont2 – egreg Apr 04 '16 at 17:37
  • See https://tex.stackexchange.com/questions/59658/use-of-tikzpicture-matrix-in-align-or-gather-environment – egreg Apr 04 '16 at 17:43
  • This solution did not work for me. It seems it depends on which range of coordinates are used by the tikzpicture itself. @Rmano's answer worked better. – jarauh Sep 13 '18 at 07:28
2

Using the comment by @greg and the answers of Align an equation and a tikz picture with anchor and baseline, I would in this case use:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{tikz}

\begin{document}

\[ A = \left(\,
        \begin{tikzpicture}[scale=0.2, 
                baseline={([yshift=-\the\dimexpr\fontdimen22\textfont2\relax]
                    current bounding box.center)},
        ] 
            \draw [magenta, line width =1mm] (0,-1) rectangle (4,3); 
            \draw [magenta, line width=1mm] (4,-1) rectangle (6,-3); 
        \end{tikzpicture} 
    \,\right)
\]

\end{document}

...to center the center of the figure with the = sign, and I would add a bit of space \, around the figure.

Result

Rmano
  • 40,848
  • 3
  • 64
  • 125