我正在尝试使用以下想法来绘制印度国旗这里以及其他一些,包括来自背面例子。我希望获得正确的编码和正确的尺寸维基百科。我对 Ashok-Chakra 的大小有疑问。有谁能帮我一下吗?我的 MWE 如下:
\documentclass[tikz]{standalone}
\definecolor{saffron}{HTML}{FF9933} % top stripe
\definecolor{white}{HTML}{FFFFFF} % middle stripe
\definecolor{indiegreen}{HTML}{138808} % bottom stripe
\definecolor{navyblue}{HTML}{000080} % ashok chakra
\tikzstyle{bharat}=[draw=navyblue,fill=navyblue]
\begin{document}
\begin{tikzpicture}
\fill[saffron] (0,400mm) rectangle (900mm,600mm);
\fill[white] (0,200mm) rectangle (900mm,400mm);
\fill[indiegreen] (0,0) rectangle (900mm,200mm);
\node at (450mm,300mm)[scale=0.09]{%
\begin{tikzpicture}
\draw[bharat, even odd rule] (0,0) circle (92.5) (0,0) circle (80);
\draw[bharat] (0,0) circle (16);
\foreach \x in {0,..., 23}{
\draw[bharat] (7.5+15*\x:80) circle (3.5);
\draw[bharat, rotate=15*\x] (0,0)--(5.38:32)--(80,0)--(-5.38:32)--cycle;
}
\end{tikzpicture}
};
\end{tikzpicture}
\end{document}
答案1
要强制执行九种不同的测量,可以使用东西.is choice
中的密钥处理程序pgfkeys
。我已经重新实现了标志代码(可能需要更多调整才能完全正确地获得 Ashoka Chakra 的细节)。请注意,对于较大尺寸的标志,需要更改x
和向量以避免错误:y
dimension too large
\documentclass[tikz,border=5]{standalone}
\definecolor{saffron}{HTML}{FF9933}
\definecolor{white}{HTML}{FFFFFF}
\definecolor{indiegreen}{HTML}{138808}
\definecolor{navyblue}{HTML}{000080}
\tikzset{%
flag width/.store in=\flagwidth,
flag height/.store in=\flagheight,
flag size/.style args={#1x#2}{flag width=#1, flag height=#2},
Ashoka Chakra/.store in=\AshokaChakra,
size/.is choice,
size/.cd,
1/.style={flag size=6300x4200, Ashoka Chakra=1295},
2/.style={flag size=3600x2400, Ashoka Chakra=740},
3/.style={flag size=2700x1800, Ashoka Chakra=555},
4/.style={flag size=1800x1200, Ashoka Chakra=370},
5/.style={flag size=1350x900, Ashoka Chakra=280},
6/.style={flag size=900x600, Ashoka Chakra=185},
7/.style={flag size=450x300, Ashoka Chakra=90},
8/.style={flag size=225x150, Ashoka Chakra=40},
9/.style={flag size=150x100, Ashoka Chakra=25},
/tikz/.cd,
Flag of India/.pic={%
\begin{scope}[#1,
local bounding box/.expanded=\pgfkeysvalueof{/tikz/name prefix}]%
\foreach \stripecolor [count=\i from 0] in {indiegreen, white, saffron}
\path [fill=\stripecolor]
(-\flagwidth/2, \i/3*\flagheight-\flagheight/2)
rectangle ++(\flagwidth, 1/3*\flagheight);
\tikzset{scale=\AshokaChakra/2}
\path [fill=navyblue, even odd rule]
circle [radius=1] circle [radius=22/25] circle [radius=1/5];
\foreach \i in {0,...,23}
\path [fill=navyblue] (15/2+15*\i:22/25) circle [radius=1/20]
[rotate=15*\i] (0:0) -- (21/4:1/3) -- (0:7/8)-- (-21/4:1/3)--cycle;
\end{scope}
},
Flag of India/.default={size=9}
}
\begin{document}
\begin{tikzpicture}[x=1mm, y=1mm]
\coordinate (flag);
\foreach \size in {5,...,9}
\pic at (flag.south) (flag)
{Flag of India={size=\size, shift=(270:\flagheight*3/4)}};
\end{tikzpicture}
\end{document}
答案2
您还有更多问题:
- 投入
pic
自己tikzpicture
是错误的做法 - 由于
scalebox
您需要pic
使用坐标乘以缩放因子的倒数。
\documentclass[tikz, border=3mm]{standalone}
\definecolor{saffron}{HTML}{FF9933} % top stripe
\definecolor{white}{HTML}{FFFFFF} % middle stripe
\definecolor{indiegreen}{HTML}{138808} % bottom stripe
\definecolor{navyblue}{HTML}{000080} % ashok chakra
\tikzset{
estilo/.style = {draw=navyblue,fill=navyblue},% moved here
ashokchakra/.pic ={
\scalebox{0.1}{
%\begin{tikzpicture} % <-- had to be deleted
\draw[estilo, even odd rule] (0,0) circle (92.5) (0,0) circle (80);
\draw[estilo] (0,0) circle (16);
\foreach \x in {0,..., 23}{
\draw[estilo] (7.5+15*\x:80) circle (3.5);
\draw[estilo, rotate=15*\x] (0,0)--(5.38:32)--(80,0)--(-5.38:32)--cycle;
\node{ \tikzpictext};
}
%\end{tikzpicture} % <-- had to be deleted
}}}
\begin{document}
\begin{tikzpicture}
\fill[saffron] (0,40) rectangle (90,60);
\fill[white] (0,20) rectangle (90,40);
\fill[indiegreen] (0, 0) rectangle (90,20);
\pic at (450,300) {ashokchakra};% <-- since you use scalebox
\end{tikzpicture}
\end{document}
scalebox
如果您不使用并手动缩放图中的所有坐标,则可以获得更好的结果pic
:
\documentclass[tikz, border=3mm]{standalone}
\definecolor{saffron}{HTML}{FF9933} % top stripe
\definecolor{white}{HTML}{FFFFFF} % middle stripe
\definecolor{indiegreen}{HTML}{138808} % bottom stripe
\definecolor{navyblue}{HTML}{000080} % ashok chakra
\begin{document}
\begin{tikzpicture}[
estilo/.style = {draw=navyblue,fill=navyblue},% moved here
ashokchakra/.pic ={
\draw[estilo, even odd rule] (0,0) circle (9.25) (0,0) circle (8);
\draw[estilo] (0,0) circle (1.6);
\foreach \x in {0,..., 23}
{
\draw[estilo] (0.75+15*\x:8.0) circle (0.35);
\draw[estilo, rotate=15*\x] (0,0)--(0.538:3.2)--(8.0,0)--(-5.38:3.2)--cycle;
}
}%end of pic
]
\fill[saffron] (0,40) rectangle (90,60);
\fill[white] (0,20) rectangle (90,40);
\fill[indiegreen] (0, 0) rectangle (90,20);
\pic at (45,30) {ashokchakra};% <-- since you use scalebox
\end{tikzpicture}
\end{document}
在上面的 MWE 中,样式ashokchakra
被移入tikzpicture
答案3
受到这里的一个解决方案的启发,没有嵌套,tikzpicture
并且对轮子进行了轻微的改动。 扩展性也很好。
\documentclass[tikz]{standalone}
\definecolor{kesara}{HTML}{FF9933} % top stripe
\definecolor{madhya}{HTML}{FFFFFF} % middle stripe
\definecolor{harita}{HTML}{138808} % bottom stripe
\definecolor{ashokaneela}{HTML}{000080} % ashok chakra
\usetikzlibrary{calc,fit}
\tikzset{
bharat/.style={ draw=ashokaneela,fill=ashokaneela }
}
\begin{document}
\begin{tikzpicture}[scale=.9]
\fill [kesara] (0,400mm) rectangle (900mm,600mm);
\node (mid) [fit={ (0,200mm) (900mm,400mm) }, rectangle, inner sep=0, fill=madhya] {};
\fill [harita] (0,0) rectangle (900mm,200mm);
\fill (mid) [ashokaneela] circle (93mm) ;
\fill (mid) [white] circle (80mm) ;
\fill (mid) [ashokaneela] circle (16mm) ;
\foreach \x in {0,..., 23}{
\fill [ashokaneela] ($ (mid) + (7.5+15*\x:80mm) $) circle (4mm) ;
\fill [ashokaneela, rotate around = {15*\x:(mid)}]
($ (mid) + (10mm,0) $) -- +(26mm,-3mm) --
($ (mid) + (92mm,0) $) -- +(-56mm,3mm) -- cycle ;
}
\end{tikzpicture}
\end{document}