我把两篇合在一起发布,因为我怀疑它们可能相关。我之前的问题,我把它们放在一个矩阵中:
\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}
这会在矩阵末尾产生一个错误:
! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options
l.33 }
;
? x
如果我尝试删除内部\tikz
命令(如链接问题的答案中所建议的那样),我会收到另一个错误:
! 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]{}}
;
?
还有第三个问题,梯队符号(即 XX 代表分区)在垂直方向上放置得太远。这似乎只发生在矩阵中。
有人有什么想法吗?
答案1
提供的命令milsymb
似乎是普通的 TikZ 绘图,您可以将它们放在矩阵的单元格中。
该软件包没有提供良好的界面来改变各种东西,但对于您来说,它就像使用普通的 TikZ 键/tikz/color
和/tikz/nodes
(这是的快捷方式/tikz/every node/.append style
)一样简单。
在第二个例子中,我使用了我自己的定义,/MilSymb/color
将其参数转发给 TikZ 及其节点。
代码
% 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}
输出
答案2
您可以使用位置键轻松地将符号放置在预定义的坐标处:
\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}
假设您可能希望根据其他链接问题更改线条和文本的颜色:
\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}