如何在 LaTeX 中绘制危险菱形(类似国家消防协会的菱形)?

如何在 LaTeX 中绘制危险菱形(类似国家消防协会的菱形)?

是否可以用 tex 制作像国家消防协会这样的菱形?我使用 xcolor 包和 [colortbl] 制作了一个表格。 美国国家防火协会

答案1

我编写了一些宏以便于使用这个钻石:

\documentclass{article}

\usepackage{tgheros,tikz}

\newcommand{\nowater}{\huge%
 \begin{tikzpicture}
  \node at (0, 0) {W};
  \draw[line width=.1ex] (-.55em, 0) -- (.55em, 0);
 \end{tikzpicture}%
}

\newcommand{\radioactive}{%
 \raisebox{.5ex}{\begin{tikzpicture}[scale=.7, rotate=60]
  \fill (0, 0) circle (.1);
  \fill (0:.15) arc (0:60:.15) -- (60:.5) arc (60:0:.5) -- cycle;
  \fill (120:.15) arc (120:180:.15) -- (180:.5) arc (180:120:.5) -- cycle;
  \fill (240:.15) arc (240:300:.15) -- (300:.5) arc (300:240:.5) -- cycle;
 \end{tikzpicture}}%
}

\newcommand{\hazarddiamond}[4]{\sffamily\huge%
 \begin{tikzpicture}[rotate=225]
  \fill[red!75] (0, 0) rectangle (1, 1);
  \fill[blue!75] (1, 0) rectangle (2, 1);
  \fill[yellow!75] (0, 1) rectangle (1, 2);
  \draw (0, 2) grid (2, 0);
  \node at (0.5, 0.5) {#1};
  \node at (1.5, 0.5) {#2};
  \node at (0.5, 1.5) {#3};
  \node at (1.5, 1.5) {\large#4};
 \end{tikzpicture}%
}

\begin{document}

\hazarddiamond{0}{0}{0}{}

\hazarddiamond{3}{1}{2}{\nowater}

\hazarddiamond{2}{4}{3}{\radioactive}

\hazarddiamond{4}{3}{3}{COR}

\end{document}

结果:

在此处输入图片描述


一种优化的解决方案是使用pics 而不是嵌套tikzpictures,这可能更为健壮:

\documentclass{standalone}
\usepackage{tikz,tgheros}

\tikzset{
    hazard diamond/.style={
        rotate=315,
        baseline=-0.5ex,
        execute at begin node={
            \sffamily
        },
        every node/.style={
            font=\huge
        }
    },
    text/.pic={
        \node[font=\large] at (0,0) {#1};
    },
    no water/.pic={
        \node at (0,0) {W};
        \draw[line width=.2ex] (-1em,0) -- (1em,0);
    },
    radioactive/.pic={
        \begin{scope}[x=0.2, y=0.2]
            \fill (0,0) circle[radius=10];
            \fill (0:15) arc[start angle=0, end angle=60, radius=15] 
                -- (60:52) arc[start angle=60, end angle=0, radius=52] -- cycle;
            \fill (120:15) arc[start angle=120, end angle=180, radius=15] 
                -- (180:52) arc[start angle=180, end angle=120, radius=52] -- cycle;
            \fill (240:15) arc[start angle=240, end angle=300, radius=15] 
                -- (300:52) arc[start angle=300, end angle=240, radius=52] -- cycle;
        \end{scope}
    },
    biohazard/.pic={
        \begin{scope}[x=0.2, y=0.2]
            \clip 
                (90:30) circle[radius=19]
                (210:30) circle[radius=19]
                (330:30) circle[radius=19];
            \fill 
                (0:27) 
                    arc[start angle=0, end angle=360, radius=27] -- (0:20)
                    arc[start angle=360, end angle=0, radius=20] -- cycle;
        \end{scope}
        \begin{scope}[x=0.2, y=0.2]
            \clip 
                (0:52) arc[start angle=0, end angle=360, radius=52]
                (90:5) -- ++(0:-1) -- ++(90:27) -- ++(0:-3) -- ++(90:20) -- ++(0:8) 
                    -- ++(90:-20) -- ++(0:-3) -- ++(90:-27) -- (90:5)
                (210:5) -- ++(120:-1) -- ++(210:27) -- ++(120:-3) -- ++(210:20) -- ++(120:8) 
                    -- ++(210:-20) -- ++(120:-3) -- ++(210:-27) -- (210:5)
                (330:5) -- ++(240:-1) -- ++(330:27) -- ++(240:-3) -- ++(330:20) -- ++(240:8) 
                    -- ++(330:-20) -- ++(240:-3) -- ++(330:-27) -- (330:5);
            \begin{scope}
                \clip 
                    (0:52) arc[start angle=0, end angle=360, radius=52]
                    (0:6) arc[start angle=360, end angle=0, radius=6]
                    (90:51) arc[start angle=90, end angle=-270, radius=21]
                    (210:51) arc[start angle=210, end angle=-150, radius=21]
                    (330:51) arc[start angle=330, end angle=-30, radius=21];
                \fill 
                    (90:22) circle[radius=30]
                    (210:22) circle[radius=30]
                    (330:22) circle[radius=30];
            \end{scope}
        \end{scope}
    }
}

\newcommand{\hazarddiamond}[5][]{%
    \begin{tikzpicture}[hazard diamond,#1]
        \fill[red!75] (0,0) rectangle (-1,1);
        \fill[blue!75] (0,0) rectangle (-1,-1);
        \fill[yellow!75] (0,0) rectangle (1,1);
        \draw (-1,-1) grid (1,1);
        \node at (-0.5,0.5) {#2};
        \node at (-0.5,-0.5) {#3};
        \node at (0.5,0.5) {#4};
        \pic at (0.5,-0.5) {#5};
    \end{tikzpicture}%
}

\begin{document}

abc \hazarddiamond{4}{3}{3}{text={COR}} def

\hazarddiamond{4}{3}{3}{no water}

\hazarddiamond{4}{3}{3}{radioactive}

\hazarddiamond{4}{3}{3}{biohazard}

\end{document}

在此处输入图片描述

答案2

\documentclass{article}
\usepackage{xcolor,txfonts,stackengine,graphicx}
\newcommand\borderdiamond[2]{%
  \stackinset{c}{}{c}{}{\textcolor{white}{\bfseries\sffamily#2}}{%
    \stackinset{c}{}{c}{}%
    {\scalebox{2.3}{\color{#1}$\Diamondblack$}}%
    {\scalebox{2.4}{$\Diamondblack$}}%
  }%
}
\begin{document}
\renewcommand\stacktype{S}
\stackon[-9.7pt]{\smash{\borderdiamond{blue}{0}\kern-2.3pt\borderdiamond{yellow}{0}}}
  {\stackanchor[-.3pt]{\borderdiamond{red}{0}}{\borderdiamond{white}{}}}
\end{document}

在此处输入图片描述

相关内容