# Sizing parentheses around tikzpicture

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}


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}


• Better yet, baseline=-\the\fontdimen22\textfont2 – egreg Apr 4 '16 at 17:37
• – egreg Apr 4 '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 7:28

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.