\tstar
可以使用 进行水平定位\hspace*{}
,但尝试使用\vspace{}
或 进行垂直定位,写入\node (x) at (somex,somey) {\tstar{}{}{}{}}
会失败。
我如何调整 \tstar 的垂直位置?
最小示例:
\documentclass[landscape,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage{pstricks}
\usepackage{fix-cm}
\usepackage{geometry}
\geometry{
top=0.5in,
inner=0.5in,
outer=0.5in,
bottom=0.5in,
headheight=3ex,
headsep=2ex,
}
\newcommand\score[2]{
\pgfmathsetmacro\pgfxa{#1+1}
\tikzstyle{scorestars}=[star, star points=5, star point ratio=2.25, draw,inner sep=0.15em,anchor=outer point 3]
\begin{tikzpicture}[baseline]
\foreach \i in {1,...,#2} {
\pgfmathparse{(\i<=#1?"yellow":"gray")}
\edef\starcolor{\pgfmathresult}
\draw (\i*1em,0) node[name=star\i,scorestars,fill=\starcolor] {};
}
\pgfmathparse{(#1>int(#1)?int(#1+1):0}
\let\partstar=\pgfmathresult
\ifnum\partstar>0
\pgfmathsetmacro\starpart{#1-(int(#1))}
\path [clip] ($(star\partstar.outer point 3)!(star\partstar.outer point 2)!(star\partstar.outer point 4)$) rectangle
($(star\partstar.outer point 2 |- star\partstar.outer point 1)!\starpart!(star\partstar.outer point 1 -| star\partstar.outer point 5)$);
\fill (\partstar*1em,0) node[scorestars,fill=yellow] {};
\fi
,\end{tikzpicture}
}
\newcommand{\tstar}[5]{% inner radius, outer radius, tips, rot angle, options
\pgfmathsetmacro{\starangle}{360/#3}
\draw[#5] (#4:#1)
\foreach \x in {1,...,#3}
{ -- (#4+\x*\starangle-\starangle/2:#2) -- (#4+\x*\starangle:#1)
}
-- cycle;
}
\begin{document}
\begin{tikzpicture}
%%% \node (st) at (x,y) {\tstar{1}{3}{27}{17}{fill=red}}; fails.
\tstar{1}{3}{27}{17}{fill=red};
\node (x) at (10,1) {{ \fontsize{100}{120}\selectfont\bf Stuff}};
\end{tikzpicture}
\end{document}
答案1
您可以将xshift
和添加yshift
到的第五个参数中\tstar
,例如
\tstar{1}{3}{27}{17}{fill=red,xshift=2cm,yshift=-5cm};
值得一提的是,使用\bfseries
not \bf
,后者已被弃用(请参阅\textit
我使用或\it
或\bfseries
等有关系吗\bf
?)。
\documentclass[landscape,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage{pstricks}
\usepackage{fix-cm}
\usepackage{geometry}
\geometry{
top=0.5in,
inner=0.5in,
outer=0.5in,
bottom=0.5in,
headheight=3ex,
headsep=2ex,
}
\newcommand\score[2]{
\pgfmathsetmacro\pgfxa{#1+1}
\tikzstyle{scorestars}=[star, star points=5, star point ratio=2.25, draw,inner sep=0.15em,anchor=outer point 3]
\begin{tikzpicture}[baseline]
\foreach \i in {1,...,#2} {
\pgfmathparse{(\i<=#1?"yellow":"gray")}
\edef\starcolor{\pgfmathresult}
\draw (\i*1em,0) node[name=star\i,scorestars,fill=\starcolor] {};
}
\pgfmathparse{(#1>int(#1)?int(#1+1):0}
\let\partstar=\pgfmathresult
\ifnum\partstar>0
\pgfmathsetmacro\starpart{#1-(int(#1))}
\path [clip] ($(star\partstar.outer point 3)!(star\partstar.outer point 2)!(star\partstar.outer point 4)$) rectangle
($(star\partstar.outer point 2 |- star\partstar.outer point 1)!\starpart!(star\partstar.outer point 1 -| star\partstar.outer point 5)$);
\fill (\partstar*1em,0) node[scorestars,fill=yellow] {};
\fi
,\end{tikzpicture}
}
\newcommand{\tstar}[5]{% inner radius, outer radius, tips, rot angle, options
\pgfmathsetmacro{\starangle}{360/#3}
\draw[#5] (#4:#1)
\foreach \x in {1,...,#3}
{ -- (#4+\x*\starangle-\starangle/2:#2) -- (#4+\x*\starangle:#1)
}
-- cycle;
}
\begin{document}
\begin{tikzpicture}
%%% \node (st) at (x,y) {\tstar{1}{3}{27}{17}{fill=red}}; fails.
\tstar{1}{3}{27}{17}{fill=red};
\tstar{1}{3}{27}{17}{fill=red,xshift=2cm,yshift=-5cm};
\node (x) at (10,1) {{ \fontsize{100}{120}\selectfont\bfseries Stuff}};
\end{tikzpicture}
\end{document}