# Correct delimiter height in TikZ

When using the left delimiter and right delimiter options, I am having the problem that their height is not equal to the node they are surrounding.

Here is an example:

\documentclass{article}

\usepackage{fullpage}
\usepackage{tikz}
\usetikzlibrary{shapes, matrix}

\begin{document}

\tikzset{
withparens/.style = {draw, outer sep=0pt,
left delimiter=(, right delimiter=),
align=center},
withbraces/.style = {draw, outer sep=0pt,
left delimiter=\{, right delimiter=\},
align=center}
}

\begin{tikzpicture}
\node[withparens] {make};
\node[right=1.5cm, withparens] {make \\ node};
\node[right=3.5cm, withparens] {make \\ node \\ higher};
\end{tikzpicture}

\vspace{2em}

\begin{tikzpicture}
\node[withbraces] {make};
\node[right=1.5cm, withbraces] {make \\ node};
\node[right=3.5cm, withbraces] {make \\ node \\ higher};
\end{tikzpicture}

\end{document}


Which produces this:

Is the height of the delimiters approximated in some way, which cannot be controlled by the user? Or are they only available in specific heights and the best (nearest) option is chosen?

• why do you use tikz? This are simple tabulars with braces? – user2478 Jul 11 '11 at 21:01
• @Herbert: This is just an MWE extracted from a more complex TikZ drawing. – Nickolay Kolev Jul 12 '11 at 2:56
• If you'd like to have the taller delim version instead, you could set \delimitershortfall=0pt (maximum space not covered by a delimiter) – morbusg Jul 12 '11 at 3:51

I had a look at the relevant code for left delimiter and right delimiter, which is located in TEXMF/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarymatrix.code.tex and called \tikz@delimiter. It places a node left or right of the main node aligned to the lower level, measures the height of the node and then executes: \left#6\vcenter{\hrule height .5#8 depth .5#8 width0pt}\right#7$%  where #6 or #7 is the delimiter depending on the side (the other is then .). Here #8 is the height of the box. As you can see it uses math code to draw the delimiter. I assume that these are only available in certain sizes and so they don't always fit. There is nothing to configure here. However, it would be possible to redefine the macro in question to scale the delimiter, e.g. using \resizebox*{!}{#8}{ .. }. \documentclass{article} \usepackage{fullpage} \usepackage{tikz} \usetikzlibrary{shapes, matrix} \makeatletter \def\tikz@delimiter#1#2#3#4#5#6#7#8{% \bgroup \pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name}% node[outer sep=0pt,inner sep=0pt,draw=none,fill=none,anchor=#1,at=(\tikz@last@fig@name.#2),#3] {% {\nullfont\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@last@fig@name}{#4}}{\pgfpointanchor{\tikz@last@fig@name}{#5}}}}% \delimitershortfall\z@% as suggested by morbusg (maximum space not covered by a delimiter = 0) \resizebox*{!}{#8}{$\left#6\vcenter{\hrule height .5#8 depth .5#8 width0pt}\right#7\$}%
}
\pgfextra{\global\let\tikz@last@fig@name=\tikz@save@last@fig@name}%
\egroup%
}
\makeatother

\begin{document}

\tikzset{
withparens/.style = {draw, outer sep=0pt,
left delimiter=(, right delimiter=),
above delimiter=(, below delimiter=),
align=center},
withbraces/.style = {draw, outer sep=0pt,
left delimiter=\{, right delimiter=\},
above delimiter=\{, below delimiter=\},
align=center}
}

\begin{tikzpicture}
\node[withparens] {make};
\node[right=1.5cm, withparens] {make \\ node};
\node[right=3.5cm, withparens] {make \\ node \\ higher};
\end{tikzpicture}

\vspace{2em}

\begin{tikzpicture}
\node[withbraces] {make};
\node[right=1.5cm, withbraces] {make \\ node};
\node[right=3.5cm, withbraces] {make \\ node \\ higher};
\end{tikzpicture}

\end{document}


I added the horizontal delimiters as well so you can see that they also work.

• Great! That might be worth to send as a patch to pgf. – Caramdir Jul 12 '11 at 1:37
• What a great answer! It seems that the horizontal delimiters are now of the perfect length, as are the vertical ones on the smallest nodes. But, the height of the vertical (left and right) delimiters on the higher nodes is still not quite there. Is this an artifact of the drawing code, or is the calculated node height #8 incorrect? – Nickolay Kolev Jul 12 '11 at 3:06
• See the comment by @morbusg above! Problem solved! – Nickolay Kolev Jul 12 '11 at 5:20
• @Nickolay: I updated my answer now to include morbusg's input. Thanks for pointing me towards it. – Martin Scharrer Jul 12 '11 at 6:45