我必须感谢 TeX Stack Exchange,尤其是这些问题:
我可以想到这个:
现在,为了让徽章看起来像第三张图片,最后的修饰是将所有粗线转换为双线(实际上,唯一真正让我烦恼的是中心的那个粗圆圈)。但我需要先合并路径。有没有一种简单的方法可以在 TikZ 中做到这一点,还是我应该保持原样?
免费奖金。我认为没有办法减少字母间距decorations.text
?
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.text,decorations.shapes,calc}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{Calibri}
\begin{document}
\thispagestyle{empty}
% Andrew Stacey's workaround for the foreach bug
\makeatletter
\def\tikz@clear@foreach{%
\let\pgffor@beginhook=\pgfutil@empty
\let\pgffor@endhook=\pgfutil@empty
\let\pgffor@afterhook=\pgfutil@empty
}
\def\tikz@plot@expression(#1){%
\edef\tikz@plot@data{\noexpand\tikz@clear@foreach\noexpand\pgfplotfunction{\expandafter\noexpand\tikz@plot@var}{\tikz@plot@samplesat}}%
\expandafter\def\expandafter\tikz@plot@data\expandafter{\tikz@plot@data{\tikz@scan@one@point\pgfutil@firstofone(#1)}}%
\tikz@@@plot%
}
\makeatother
% #1 number of teeths
% #2 radius intern
% #3 radius extern
% #4 angle from start to end of the first arc
% #5 angle to decale the second arc from the first
\newcommand{\gear}[5]{%
\draw[rotate=-4] (0:#2)
\foreach \i in {1,...,#1} {%
{[rotate=(\i-1)*360/#1] -- (0:#2) arc (0:#4:#2) {
-- (#4+#5:#3) arc (#4+#5:360/#1-#5:#3)}}
} -- cycle;}
\begin{tikzpicture}[remember picture,overlay]
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
(current page.south east) --
(current page.south west) --
(current page.north west) --
(current page.north east)}
]
\begin{pgfinterruptboundingbox} % To make sure our clipping path does not mess up the placement of the picture
% The small disk at center will stay white (first inverse clip selection)
\path[clip] circle (0.715) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}
% Both curves that cut the gear
\draw[line width=2pt] (175:1.33) .. controls +(-5:2) and +(186:0.2) .. (6:2);
\draw[line width=2pt] (185:1.33) .. controls +(-5:2) and +(186:0.2) .. (-9:2);
\begin{pgfinterruptboundingbox}
% The arrow will cover the gear (second inverse clip selection)
\path[clip] (175:1.25) arc (175:185:1.25) .. controls +(-5:2) and +(186:0.2) .. (-7.47:2.1) arc (-7.47:5.1:2.1) .. controls +(186:0.2) and +(-5:2) .. (175:1.33) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}
% The gear, and the smallest circle
\gear{14}{1.05}{1.25}{10.5}{2}
\draw[line width=2pt] circle (0.75);
% Thick circles with the text
\draw[line width=2pt] circle (1.33) circle (2);
\draw[decorate,decoration={shape sep=5mm,text along path,raise=1.5mm,text={|\fontsize{16.5}{16.5}\selectfont|PROLOGIN 2013||}}] (172:1.33) arc (172:8:1.33);
% Arrow tips
\draw[line width=2pt] (10.5:2) .. controls +(-5:0.3) and +(185:0.3) .. (6:3.8) .. controls +(0,-0.2) and +(0.2,0) .. (-20:2);
% Beginning of arrow
\draw[line width=2pt] (168:2) .. controls +(190:0.36) and +(175:0.36) .. (175:2);
\draw[line width=2pt] (162:2) .. controls +(190:0.7) and +(175:0.7) .. (180:2);
\end{tikzpicture}
\end{document}
答案1
您的路径太复杂,无法合并。由于实际显示的路径部分使用剪辑定义,因此合并路径的结果可能并不完全符合您的要求。关键是剪辑不是在构建路径时应用,而是在渲染路径时应用。因此,如果您保存一条路径以便稍后将其与另一条路径合并,则该剪辑在保存的路径中不会很明显。
因此,要利用该double
键来实现您想要的效果,您需要定义路径而不是使用剪辑。但是一旦您这样做了,您很可能会发现,您可以简单地将要组合的路径放在一个\draw
命令中,从而在定义时将它们组合起来。
另一种选择(我在评论中提到过)是简单地绘制两次图片,一次用粗黑线,一次用细白线。这相对简单 - 这是执行此操作的代码的修改。如您所见,它需要进行一些调整:我选择的线条粗细意味着您的剪辑应该略作修改。为此,我将代码分成两半,以便只有应该加倍的位才会加倍(当然,我可能错了)。
关于你的“奖励”问题,装饰路径的自动机似乎不能后退。因此,为了将字母挤在一起,必须阻止它向前移动太多。自动机所做的是:测量下一个字母,向前移动一半长度,排版字母,向前移动一半长度,可能增加额外的移位。额外的移位已经在 0pt,因此变化的空间在于移位。我所做的是放入一个代码来修改它,以便它向前移动X乘以其长度。这可能不是正确的方法,但却是最简单的方法。
代码如下:
\documentclass[11pt]{article}
%\url{http://tex.stackexchange.com/q/67746/86}
\usepackage{tikz}
\usetikzlibrary{decorations.text,decorations.shapes,calc}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{Calibri}
\tikzset{
reverseclip/.style={
insert path={(current page.north east) --
(current page.south east) --
(current page.south west) --
(current page.north west) --
(current page.north east)}
}
}
\thispagestyle{empty}
% Andrew Stacey's workaround for the foreach bug
\makeatletter
\def\tikz@clear@foreach{%
\let\pgffor@beginhook=\pgfutil@empty
\let\pgffor@endhook=\pgfutil@empty
\let\pgffor@afterhook=\pgfutil@empty
}
\def\tikz@plot@expression(#1){%
\edef\tikz@plot@data{\noexpand\tikz@clear@foreach\noexpand\pgfplotfunction{\expandafter\noexpand\tikz@plot@var}{\tikz@plot@samplesat}}%
\expandafter\def\expandafter\tikz@plot@data\expandafter{\tikz@plot@data{\tikz@scan@one@point\pgfutil@firstofone(#1)}}%
\tikz@@@plot%
}
\pgfkeys{
/pgf/decoration/squeeze text/.code={%
\expandafter\g@addto@macro\csname pgf@decorate@@text along path@after typeset@options\endcsname{,width=+#1\wd\pgf@lib@dec@text@box}%
\expandafter\g@addto@macro\csname pgf@decorate@@text along path@before typeset@options\endcsname{,width=+#1\wd\pgf@lib@dec@text@box}%
}
}
% #1 number of teeths
% #2 radius intern
% #3 radius extern
% #4 angle from start to end of the first arc
% #5 angle to decale the second arc from the first
\newcommand{\gear}[5]{%
\draw[rotate=-4] (0:#2)
\foreach \i in {1,...,#1} {%
{[rotate=(\i-1)*360/#1] -- (0:#2) arc (0:#4:#2) {
-- (#4+#5:#3) arc (#4+#5:360/#1-#5:#3)}}
} -- cycle;}
\newcommand{\drawlogo}[1]{%
\begin{tikzpicture}[remember picture,overlay,bronze/.style={#1}]
\useasboundingbox (-3,-2.5) rectangle (4,2.5);
\begin{pgfinterruptboundingbox} % To make sure our clipping path does not mess up the placement of the picture
% The small disk at center will stay white (first inverse clip selection)
\path[clip] circle (0.715) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}
% Both curves that cut the gear
\draw[bronze] (175:1.33) .. controls +(-5:2) and +(186:0.2) .. (6:2);
\draw[bronze] (185:1.33) .. controls +(-5:2) and +(186:0.2) .. (-9:2);
\begin{pgfinterruptboundingbox}
% The arrow will cover the gear (second inverse clip selection)
\path[clip] (175:1.25) arc (175:185:1.25) .. controls +(-5:2) and +(186:0.2) .. (-7.47:2.1) arc (-7.47:5.1:2.1) .. controls +(186:0.2) and +(-5:2) .. (175:1.33) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}
% The gear, and the smallest circle
%\gear{14}{1.05}{1.25}{10.5}{2}
\draw[bronze] circle (0.75);
% Thick circles with the text
\draw[bronze] circle (1.33) circle (2);
%\draw[decorate,decoration={shape sep=5mm,text along path,raise=1.5mm,text={|\fontsize{16.5}{16.5}\selectfont|PROLOGIN 2013||}}] (172:1.33) arc (172:8:1.33);
% Arrow tips
\draw[bronze] (10.5:2) .. controls +(-5:0.3) and +(185:0.3) .. (6:3.8) .. controls +(0,-0.2) and +(0.2,0) .. (-20:2);
% Beginning of arrow
\draw[bronze] (168:2) .. controls +(190:0.36) and +(175:0.36) .. (175:2);
\draw[bronze] (162:2) .. controls +(190:0.7) and +(175:0.7) .. (180:2);
\end{tikzpicture}%
}
\newcommand{\decoratelogo}{%
\begin{tikzpicture}[remember picture,overlay]
\useasboundingbox (-3,-2.5) rectangle (4,2.5);
\begin{pgfinterruptboundingbox} % To make sure our clipping path does not mess up the placement of the picture
% The small disk at center will stay white (first inverse clip selection)
\path[clip] circle (0.715) -- cycle [reverseclip];
% The arrow will cover the gear (second inverse clip selection)
\path[clip] (175:1.25) arc (175:185:1.25) .. controls +(-5:2) and +(186:0.2) .. (-7.47:2.1) arc (-7.47:5.1:2.1) .. controls +(186:0.2) and +(-5:2) .. (175:1.33) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}
% The gear
\gear{14}{1.05}{1.25}{10.5}{2}
\draw[decorate,decoration={shape sep=5mm,text along path,squeeze text=.4,raise=1.5mm,text={|\fontsize{16.5}{16.5}\selectfont|PROLOGIN 2013 ||}}] (172:1.33) arc (172:8:1.33);
\end{tikzpicture}%
}
\begin{document}
\drawlogo{line width=6pt,black}%
\drawlogo{line width=2pt,white}%
\decoratelogo
\end{document}
(其他细微修改:将定义移至 之前\begin{document}
并更改\tikzstyle
为\tikzset
)
结果:
我意识到这并没有完全回答你关于组合路径的问题。如果你真的想通过组合路径来实现这一点,那么正如我上面所说,你需要改变你定义图片的方式。所以如果你想要一个使用组合路径的解决方案,找出重新定义并相应地编辑问题。
我希望我所做的能够帮助您完成绘图的下一步。