3

studding CarLaTeX answer on question i find unexpected behavior of tikz matrix delimiter: if the size of math nodes are determined by text width=... and text height=..., than delimiters work as expected, however, if i replace them with minimum size=... gives error !missing } inserted.. <inserted text> }. test example:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{matrix}
\newcommand\x{\times}

\begin{document}
\begin{tikzpicture}
\matrix [matrix of math nodes,
         nodes={rectangle, %draw, very thin,
                minimum size=1.2em, text depth=0.25ex,
                inner sep=0pt, outer sep=0pt,
                left delimiter=(, right delimiter=),
                fill opacity=0.5, text opacity=1,
                anchor=center},
         column sep=-0.5\pgflinewidth,
         row sep=-0.5\pgflinewidth,
         column 2/.append style = {nodes={fill=cyan!50}},
         row 2/.append style = {nodes={fill=cyan!50}},
         row 2 column 2/.append style={nodes={fill=cyan}},
         ]
{
a_1 & \x  & a_3 \\
a_4 & \x  & a_6 \\
a_7 & \x  & a_9 \\
};
\end{tikzpicture}
\end{document}

if i comment definition of delimiters, example gives:

enter image description here

do i miss something or doing wrong?

Zarko
  • 296,517
  • I get errors rather from ampersand replacement and the left delimiter/right delimiter line. minimum size works as well for me as text width or text height. – Jasper Habicht Feb 17 '18 at 23:56
  • ups, line with ampersant replacement was left from some my experiments ... it should be erased. done now in question. – Zarko Feb 17 '18 at 23:59

1 Answers1

4

You should place left delimiter=(, right delimiter=) outside of the nodes option.

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{matrix}
\newcommand\x{\times}

\begin{document}
\begin{tikzpicture}
\matrix [matrix of math nodes,
         nodes={rectangle, %draw, very thin,
                minimum size=1.2em, text depth=0.25ex,
                inner sep=0pt, outer sep=0pt,
                fill opacity=0.5, text opacity=1,
                anchor=center},
         column sep=-0.5\pgflinewidth,
         row sep=-0.5\pgflinewidth,
         column 2/.append style = {nodes={fill=cyan!50}},
         row 2/.append style = {nodes={fill=cyan!50}},
         row 2 column 2/.append style={nodes={fill=cyan}},
         left delimiter={(}, right delimiter={)}
         ]
{
a_1 & \x  & a_3 \\
a_4 & \x  & a_6 \\
a_7 & \x  & a_9 \\
};
\end{tikzpicture}
\end{document}

enter image description here

  • what a stupid mistake ... thank you for finding it in my example. howver, now i'm confused. if you look @CarlaTeX answer in given ling, and there replace line nodes={text width=.75em, text height=1.75ex, text depth=.5ex, align=center} with nodes={minimum size=1.5em, text depth=.5ex, align=center}, you will receive error: Missing $ inserted <inserted text> $.before accepting your answer, i should check all my experiments again, for now +1 :-) – Zarko Feb 18 '18 at 00:49
  • Jasper Habicht, i done even more stupid error when testing @carlatex answer :-(. in it i had combination minimum size=...,align=center which is of course wrong ... what embarrassing! – Zarko Feb 18 '18 at 11:35