0

This is a follow-up to On drawing a crystal graph, I have a trouble: ! Illegal parameter number in definition of \cmdGR@vertex@L: I would like to use tkz-graph and label a vertex with something a little complicated: a diagram of the form

1 1
2

with boxes around the numbers, like this: Young tableau

Sample LaTeX code to produce this diagram:

{\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}\raisebox{-.6ex}
{$\begin{array}[b]{*{2}c}\cline{1-2}\lr{1}&\lr{1}\\\cline{1-2}\lr{2}\\\cline{1-1}\end{array}$}}

If I use this as quoted below, I get an error as in the cited question:

! Illegal parameter number in definition of \cmdGR@vertex@L.
<to be read again> 
                   1
l.51 ...end{array}$}}$},x=5cm,y=1cm]{v0}

As noted in the cited question, this arises in code from Sage and in particular from a bug in Sage, and I would like to fix that bug by improving the LaTeX code. The "sample" code above is what Sage currently uses, so that's what I would like to replace.

A sample file that produces the error, and if you remove the offending tikzpicture, you can see what the vertex label should look like:

\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
%
\Vertex[L=\hbox{${\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}\raisebox{-.6ex}{$\begin{array}[b]{*{2}c}\cline{1-2}
\lr{1}&\lr{1}\\\cline{1-2}\lr{2}\\\cline{1-1}\end{array}$}}$},x=5cm,y=1cm]{v0}
%
\end{tikzpicture}

The desired vertex label:
\[
\hbox{${\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}\raisebox{-.6ex}
{$\begin{array}[b]{*{2}c}\cline{1-2}\lr{1}&\lr{1}\\\cline{1-2}\lr{2}\\\cline{1-1}\end{array}$}}$}
\]

\end{document}

1 Answer 1

2

The issue is where lr is defined. It needs to be defined outside of the \Vertex command. In there, you cannot use \multicolumn{...}{...}{...}. There are multiple ways to overcome this:

  • The cleanest approach: don't use multicolumn but add the vertical lines in the array arguments using {*n{|c}|}, where n is the number of columns in the array. Also, \lr{...} will be redundant but it is there in case you wanted to customize the look of each cell
\documentclass{article}
\usepackage{tkz-graph}

\begin{document}
    \begin{tikzpicture}[VertexStyle/.append style={draw=none, fill=none}]
        \def\lr#1{#1}
        \Vertex[L=
        $\begin{array}{*2{|c}|}\cline{1-2}
        \lr{A}&\lr{B}\\\cline{1-2}
        \lr{C}\\\cline{1-1}
        \end{array}$
        ,x=5cm,y=1cm]{v0}
    \end{tikzpicture}
\end{document}

First approach output

  • The second approach is similar to the first one but includes some of the other commands
\documentclass{article}
\usepackage{tkz-graph}

\begin{document}
    \begin{tikzpicture}[VertexStyle/.append style={draw=none, fill=none}]
        \def\lr#1{#1}
        \Vertex[L=
        \hbox{
        ${
        \raisebox{-.6ex}{
        $\begin{array}[b]{*{2}{|c}|}\cline{1-2}
        \lr{1}&\lr{1}\\\cline{1-2}
        \lr{2}\\\cline{1-1}
        \end{array}
        $}}$
        },x=5cm,y=1cm]{v0}
        %
    \end{tikzpicture}
\end{document}

Second approach output

  • BONUS: A more compact version of the first approach
\documentclass{article}
\usepackage{tkz-graph}

\newcommand{\myVertex}[5]{%
\Vertex[L=$\begin{array}{*#2{|c}|}#1\end{array}$,x=#3,y=#4]{#5}%
}

\begin{document}
    \begin{tikzpicture}[VertexStyle/.append style={draw=blue, fill=none}]
        \myVertex{
        \cline{1-3}
        A&B&C\\\cline{1-3}
        D&E\\\cline{1-2}
        F\\\cline{1-1}
        }{3}{1cm}{1cm}{v0}

        \myVertex{
        \cline{1-3}
        1&2&3\\\cline{1-3}
        4&5\\\cline{1-2}
        6\\\cline{1-1}
        }{3}{3cm}{1cm}{v1}
    \end{tikzpicture}
\end{document}

Bonus approach output


Original Answer:

Output

\documentclass{article}
\usepackage{tkz-graph}

\begin{document}
    \begin{tikzpicture}
        \def\lr#1{#1}%keep it aligned with the code generated and for cell customization
        %
        \tikzset{VertexStyle/.append style={draw=none}}
        \Vertex[L=\hbox{
        $
        \begin{array}{|c|c|}\cline{1-2}
        \lr{1}&\lr{1}\\\cline{1-2}
        \lr{2}\\\cline{1-1}
        \end{array}
        $}
        ,x=5cm,y=1cm]{v0}
        %
    \end{tikzpicture}
\end{document}
1
  • Thank you, this works for me and gives me some ideas for fixing it in Sage. Jun 6, 2022 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .