1

Am posting two in one as I suspect these may be related. Following on from my previous question, I am putting them in a matrix:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{milsymb}
\usetikzlibrary{matrix}

\makeatletter
\protected\def\tikz@fig@main#1{%
  \expandafter\gdef\csname labeltextof@\tikz@fig@name\endcsname{#1}%
  \iftikz@node@is@pic%
    \tikz@node@is@picfalse%
    \tikz@subpicture@handle{#1}%
  \else%
    \tikz@@fig@main#1\egroup%
  \fi}
\makeatother

\newcommand\labeltextof[1]{\csname labeltextof@#1\endcsname}
\newcommand{\aftercolorof}[2]{% #1 is the color, #2 us the node
  \path (#2.center) node[#1] (#2-2) {\labeltextof{#2}};
}

\begin{document}

\begin{tikzpicture}

\matrix[row sep=2mm, column sep=1mm]{
  \node (nA) {\tikz{\MilLand[faction=friendly,monochrome,echelon=division,main=armoured,fill=green]{}}};
  \node (nA) {\tikz{\MilLand[faction=friendly,monochrome,echelon=division,main=armoured,fill=yellow]{}}};
  &
  \node (nA) {\tikz{\MilLand[faction=friendly,monochrome,echelon=division,main=armoured,fill=green]{}}};
  \node (nA) {\tikz{\MilLand[faction=friendly,monochrome,echelon=division,main=armoured,fill=yellow]{}}};
  \\
};

%\aftercolorof{red}{nA}
\end{tikzpicture}

\end{document}

This produces an error at the end of the matrix:

! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options 
                                             
l.33 }
      ;
? x

And if I try to remove the inner \tikz command, as suggested in the answer to the linked question, I get another error:

! LaTeX Error: Environment scope undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.25 ...elon=division,main=armoured,fill=green]{}}
                                                  ;
? 

There is a third problem also, that the echelon symbol (ie XX for division) is put too far away vertically. This seems to happen only in matrix.

Any ideas anybody?

1
  • 1
    You should never have a tikzpicture inside another tikzpicture. The \tikz{...} command is just a shortcut for \begin{tikzpicture}...\end{tikzpicture}. I strongly recommend rewriting the code to avoid this nesting (here and in the previous question).
    – Sandy G
    Mar 24 at 17:46

2 Answers 2

2

The commands that milsymb provide seem to be ordinary TikZ drawings, you can just put those in the cells of a matrix.

The package doesn't provide nice interfaces to change various things but in your case it's as easy as using just the ordinary TikZ keys /tikz/color and /tikz/nodes (which is a shortcut to /tikz/every node/.append style).

In the second example, I've used my own definition of /MilSymb/color that forwards its argument to TikZ and its nodes.

Code

% temporary workaround for
% https://github.com/ralphieraccoon/MilSymb/commit/72df32af60b99e4213fdf244e41407de27f8ca0a
\begin{filecontents}{tikzlibraryshapes.Symbols.code.tex}
\usetikzlibrary{shapes.symbols}
\end{filecontents}
%
\documentclass{standalone}
\usepackage{tikz}
\usepackage{milsymb}
\pgfqkeys{/MilSymb}{color/.style={/tikz/color={#1},/tikz/nodes={/tikz/color={#1}}}}
\begin{document}

\begin{tikzpicture}
\matrix[row sep=2mm, column sep=1mm]{
  \MilLand[faction=friendly, monochrome, echelon=division, main=armoured,
    /tikz/red, /tikz/nodes=red, fill=green]{}
& \MilLand[faction=friendly, monochrome, echelon=division, main=armoured,
    color=red, fill=yellow]{}
\\
  \MilLand[faction=friendly, monochrome, echelon=division,
    main=armoured, fill=green]{}
& \MilLand[faction=friendly, monochrome, echelon=division,
    main=armoured, fill=yellow]{}
\\};
\end{tikzpicture}
\end{document}

Output

enter image description here

0
1

You can easily place the symbols at predefined coordinates using the location key:

\documentclass{standalone}
\usepackage{milsymb}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}

\matrix[matrix of nodes, 
    every node/.style={minimum width=1.75cm, minimum height=1.75cm}
] (m) {
  {} & {} \\
  {} & {} \\
};

\MilLand[faction=friendly, echelon=division, main=armoured, fill=green] (m-1-1)
\MilLand[faction=friendly, echelon=division, main=armoured, fill=yellow] (m-1-2)
\MilLand[faction=friendly, echelon=division, main=armoured, fill=green] (m-2-1)
\MilLand[faction=friendly, echelon=division, main=armoured, fill=yellow] (m-2-2)

\end{tikzpicture}
\end{document}

enter image description here


Assuming that you might wish to change the color of the lines and text as per your other linked question:

\documentclass{standalone}
\usepackage{milsymb}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}

\matrix[matrix of nodes, 
    every node/.style={minimum width=1.75cm, minimum height=1.75cm}
] (m) {
  {} & {} \\
  {} & {} \\
};

\begin{scope}
\pgfsetstrokecolor{red}
\MilLand[faction=friendly, echelon=division, main=armoured, fill=green, red] (m-1-1)
\MilLand[faction=friendly, echelon=division, main=armoured, fill=yellow, red] (m-1-2)
\end{scope}
\MilLand[faction=friendly, echelon=division, main=armoured, fill=green] (m-2-1)
\MilLand[faction=friendly, echelon=division, main=armoured, fill=yellow] (m-2-2)

\end{tikzpicture}
\end{document}

enter image description here

2
  • @TomasBy The problem is that the package uses pics to draw the symbols, but it does not apply pic actions which would allow to forward arbitrary custom styles to these pics. Therefore, I applied Sam Carter's nice idea of setting the line color using \pgfsetstrokecolor, but additionally I used a scope to only apply this setting of the color to a certain group of items. Mar 24 at 19:43
  • 1
    I had missed Sam's comment, as the answer was updated I think. Now the colours work.
    – Tomas By
    Mar 24 at 19:59

You must log in to answer this question.

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