我正在尝试使用 TikZ 创建三个道路符号。这些是
- 美国州际公路盾形路标
- 美国公路盾构
- 通用州际公路“药丸”。这基本上是一个顶部有两个半圆的矩形。
我已经创建了一个像这样的包......
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{roadsymbols}[Some TiKz picutres for road symbols]
\RequirePackage{tikz}
% interstate
% TODO Use U.S. Intertate Shield
\newcommand{\istate}[1]{%
\begin{tikzpicture}
\node {#1};
\end{tikzpicture}
}
% national highway
% TODO Use U.S. Highway Shield
\newcommand{\hwy}[1]{%
\begin{tikzpicture}
\node {#1};
\end{tikzpicture}
}
% state highway
\newcommand{\shwy}[1]{%
\begin{tikzpicture}
\node (0,0) {#1};
\draw (-8pt, 6pt) -- (8pt, 6pt);
\draw (-8pt, -6pt) -- (8pt, -6pt);
\draw (-8pt, 6pt) arc (90:270:6pt);
\draw (8pt, 6pt) arc (90:-90:6pt);
\end{tikzpicture}
}
% TODO Can these be make to fix the text they contain _horizontally_?
我已经能够制作出“药丸”,如上所示。
这个想法是有一个命令可以打印出只是轮廓这些符号中含有给定的文本。我对 TikZ 不熟悉,老实说,我不知道如何开始以准确的方式处理更复杂的形状。作为奖励,符号可以是固定高度(略大于其中的文本大小),但理想情况下它们会水平增长以适应。我的药丸现在无法进行这种拉伸。
答案1
欢迎来到 TeX.SE!!! 这是第一个盾牌的示例,使用 Ti钾Zspath3
库。我认为,对于很多剪辑(非常大的数量),你可以做同样的事情,但我更喜欢这样做。
设置舞台: 让我们找到盾牌及其各部分的轮廓:
\documentclass[tikz,border=1.618mm]{standalone}
\begin{document}\sffamily\bfseries
\begin{tikzpicture}
\foreach\j in {0,0.1}
{
\foreach\i in {-1,1}
{
\draw (0.5*\i,0.5) circle (2.5-\j);
\draw (0.75*\i,4.4) circle (2.5+\j);
}
\draw (-2,1.1+\j) --++ (4,0);
}
\node[yscale=1.4] at (0, 1.5) {\large INTERSTATE};
\node[scale =3.5] at (0,-0.1) {\huge 80};
\end{tikzpicture}
\end{document}
现在开始脏活:让我们拿起喷灯开始工作吧,有很多东西需要切割和焊接。
\documentclass[tikz,border=1.618mm]{standalone}
\usetikzlibrary{intersections,spath3}
\definecolor{interstate blue}{HTML}{003F87}
\definecolor{interstate red} {HTML}{Af1E2D}
\begin{document}\sffamily\bfseries
\begin{tikzpicture}
\useasboundingbox (-2.1,-2) rectangle (2.1,2.1);
% creating the paths
\path[spath/save=circleBLO] (-0.5 ,0.5) circle (2.5); % circle bottom left outer
\path[spath/save=circleBRO] (0.5 ,0.5) circle (2.5); % circle bottom right outer
\path[spath/save=circleBLI] (-0.5 ,0.5) circle (2.4); % circle bottom left inner
\path[spath/save=circleBRI] (0.5 ,0.5) circle (2.4); % ...
\path[spath/save=circleTLO] (-0.75,4.4) circle (2.5);
\path[spath/save=circleTRO] (0.75,4.4) circle (2.5);
\path[spath/save=circleTLI] (-0.75,4.4) circle (2.6);
\path[spath/save=circleTRI] (0.75,4.4) circle (2.6);
\path[spath/save=lineB] (-2 ,1.1) --++ (4,0); % line bottom
\path[spath/save=lineT] (-2 ,1.2) --++ (4,0); % line top
% spath3 operatios
\tikzset
{% circles have non-visible components, we don't need them
spath/remove empty components={circleBLO},
spath/remove empty components={circleBRO},
spath/remove empty components={circleBLI},
spath/remove empty components={circleBRI},
spath/remove empty components={circleTLO},
spath/remove empty components={circleTRO},
spath/remove empty components={circleTLI},
spath/remove empty components={circleTRI},
% cutting
spath/split at intersections={circleBLO}{circleBRO},
spath/split at intersections={circleTLO}{circleTRO},
spath/split at intersections={circleBLO}{circleTRO},
spath/split at intersections={circleBRO}{circleTLO},
spath/split at intersections={circleBLI}{circleBRI},
spath/split at intersections={circleBLI}{circleTRI},
spath/split at intersections={circleBRI}{circleTLI},
spath/split at intersections={circleTLI}{circleTRI},
spath/split at intersections={circleBLI}{lineB},
spath/split at intersections={circleBRI}{lineB},
spath/split at intersections={circleBLI}{lineT},
spath/split at intersections={circleBRI}{lineT},
% store the pieces
spath/get components of={circleBLO}\cBLO,
spath/get components of={circleBRO}\cBRO,
spath/get components of={circleTLO}\cTLO,
spath/get components of={circleTRO}\cTRO,
spath/get components of={circleBLI}\cBLI,
spath/get components of={circleBRI}\cBRI,
spath/get components of={circleTLI}\cTLI,
spath/get components of={circleTRI}\cTRI,
spath/get components of={lineB}\lB,
spath/get components of={lineT}\lT,
}
% shield
\draw[
spath/use=\getComponentOf\cBLO{3},
spath/use={\getComponentOf\cTRO{3},reverse,weld},
spath/use={\getComponentOf\cTLO{2},reverse,weld},
spath/use={\getComponentOf\cBRO{2},weld},
];
% 80
\fill[interstate blue,
spath/use=\getComponentOf\cBLI{3},
spath/use={\getComponentOf\lB{1},weld},
spath/use={\getComponentOf\cBRI{4},weld},
];
% interstate
\fill[interstate red,
spath/use=\getComponentOf\cBLI{5},
spath/use={\getComponentOf\cTRI{2},reverse,weld},
spath/use={\getComponentOf\cTLI{1},reverse,weld},
spath/use={\getComponentOf\cBRI{2},weld},
spath/use={\getComponentOf\lT{2},weld},
];
% labels
\node[yscale=1.4,white] at (0, 1.5) {\large INTERSTATE};
\node[scale =3.5,white] at (0,-0.1) {\huge 80};
\end{tikzpicture}
\end{document}