我有一个足球场模板,然后我有一个硬编码的参数列表,用于设置他们在足球场上的位置。我使用了 3 个参数:球衣号码、球员姓名、(第一个坐标、第二个坐标)。但很难使其动态化并改变场地位置。我想使用两个数据表:球员 {球衣号码,姓名} 和位置 {守门员,(坐标)}。我该怎么做?
我的代码:
\SoccerStrikers{Jersey Number:1}{Player1}{(.5,4.5)}
\SoccerStrikers{35}{Player2}{(3.2,8)}
\SoccerStrikers{9}{Player3}{(1.8,6)}
\SoccerStrikers{7}{Player4}{(1.8,3)}
\SoccerStrikers{10}{Player5}{(3.2,1)}
\SoccerStrikers{91}{Player6}{(3.7,4.5)}
\SoccerStrikers{5}{Player7}{(6.5,7.5)}
\SoccerStrikers{12}{Player8}{(5.5,5.5)}
\SoccerStrikers{6}{Player9}{(5.5,3.5)}
\SoccerStrikers{15}{Player10}{(6.5,1.5)}
\SoccerStrikers{22}{Player11}{(8.2,4.5)}
答案1
虽然不知道您打算用它做什么,但以下使用expl3
和属性列表来存储信息。每个访问都是完全可扩展的,存储当然不是。
\documentclass[]{article}
\ExplSyntaxOn
\prop_new:N \g_saupa_players_names_prop
\prop_new:N \g_saupa_players_numbers_prop
\prop_new:N \g_saupa_players_positions_prop
\prop_new:N \g_saupa_players_coords_prop
\NewDocumentCommand \newplayer { m m m m m }
{ \saupa_new_player:nnnnn {#1} {#2} {#3} {#4} {#5} }
\cs_new_protected:Npn \saupa_new_player:nnnnn #1#2#3#4#5
{
\prop_if_in:NnTF \g_saupa_players_names_prop {#1}
{ \msg_error:nnn { saupa } { player-already-known } {#1} }
{
\prop_gput:Nnn \g_saupa_players_names_prop {#1} {#2}
\prop_gput:Nnn \g_saupa_players_numbers_prop {#1} {#3}
\prop_gput:Nnn \g_saupa_players_positions_prop {#1} {#4}
\prop_gput:Nnn \g_saupa_players_coords_prop {#1} {#5}
}
}
\NewExpandableDocumentCommand \playername { m }
{ \prop_item:Nn \g_saupa_players_names_prop {#1} }
\NewExpandableDocumentCommand \playernumber { m }
{ \prop_item:Nn \g_saupa_players_numbers_prop {#1} }
\NewExpandableDocumentCommand \playerposition { m }
{ \prop_item:Nn \g_saupa_players_positions_prop {#1} }
\NewExpandableDocumentCommand \playercoordinates { m }
{ \prop_item:Nn \g_saupa_players_coords_prop {#1} }
\NewExpandableDocumentCommand \drawplayer { O{gray} m }
{
\draw[fill=#1]
(\playercoordinates{#2})
circle[radius=1] node[below]{\playername{#2}}
;
}
\ExplSyntaxOff
\newplayer{me}{Skillmon}{43}{Answerer}{5,7}
\newplayer{saupa}{Saupa}{1}{Asker}{-40,15}
\usepackage{tikz}
\begin{document}
The player \playername{me} has the number \playernumber{me} plays on
position \playerposition{me} and should be placed at
(\playercoordinates{me}).
The player \playername{saupa} has the number \playernumber{saupa} plays on
position \playerposition{saupa} and should be placed at
(\playercoordinates{saupa}).
\begin{tikzpicture}[x=1mm,y=1mm]
\draw
(-52.5,-34.75) coordinate(bl) rectangle (52.5,34.75) coordinate(tr)
(0,0) coordinate(c) circle[radius=9.15]
(c|-bl) -- (c|-tr)
;
\draw
(c-|bl) +(0,-9.16) rectangle +(5.5, 9.16)
+(0,-20.16) rectangle +(16.5, 20.16)
;
\fill
(c) circle[radius=.24]
(c-|bl) +(11,0) coordinate(pl) circle[radius=.24]
;
\begin{scope}
\clip (c-|bl) ++(16.5,9.15)rectangle++(9.15,-18.3);
\draw (pl) circle[radius=9.15];
\end{scope}
\draw
(c-|tr) +(0,-9.16) rectangle +(-5.5, 9.16)
+(0,-20.16) rectangle +(-16.5, 20.16)
;
\fill
(c) circle[radius=.24]
(c-|tr) +(-11,0) coordinate(pr) circle[radius=.24]
;
\begin{scope}
\clip (c-|tr) ++(-16.5,9.15)rectangle++(-9.15,-18.3);
\draw (pr) circle[radius=9.15];
\end{scope}
\drawplayer{me}
\drawplayer{saupa}
\end{tikzpicture}
\end{document}