我承认自己不擅长用 LaTeX 画图,只能复制粘贴,然后尽可能地进行调整。我看了http://www.texample.net但找不到任何可以改编的东西。我想创建一组交通信号灯的图像,文字在一侧,如下图所示。我想将其用作分数系统的一部分,其中每种颜色都有某种含义。我可能正在寻找两个项目。下面的图片,然后只是交通信号灯,我可以将分数放在它所属的灯中。
PS:抱歉,我没有 MWE,但不知道从哪里开始。 PPS:抱歉,请帮我画这张附图。
答案1
\documentclass[border=2mm, tikz]{standalone}
\usetikzlibrary{matrix, positioning}
\tikzset{
trafficlight/.style = {%
matrix of nodes,
nodes in empty cells,
rounded corners,
draw = blue!70,
fill = blue!30,
nodes = {circle, minimum size=5mm, anchor=center, draw=black},
row 1/.style={nodes={fill=red}},
row 2/.style={nodes={fill=yellow}},
row 3/.style={nodes={fill=green}},
row sep=3mm,
}
}
\begin{document}
\begin{tikzpicture}
\matrix[trafficlight] (A) { \\ \\ \\};
\node[right= 2mm of A-1-1] {Score 1};
\node[right= 2mm of A-2-1] {Score 2};
\node[right= 2mm of A-3-1] {Score 3};
\end{tikzpicture}
\end{document}
答案2
\documentclass{article}
\usepackage{stackengine,amssymb,xcolor}
\setstackgap{L}{16pt}
\savestack\trafficlight{%
\stackinset{c}{.1pt}{c}{-1pt}{%
\Longstack{\textcolor{red}{\Huge$\bullet$} \textcolor{yellow}{\Huge$\bullet$}
\textcolor{green}{\Huge$\bullet$}}%
}{\textcolor{blue!30!gray}{\rule[-1ex]{3.5ex}{4\baselineskip}}}%
}
\begin{document}
\setstackEOL{\\}
\Longstack[l]{Score 21--30\\ Score 11--20\\ Score 1--10} \trafficlight
\end{document}
...或者如果不需要相应的侧面文字。
\documentclass{article}
\usepackage{stackengine,amssymb,xcolor}
\setstackgap{S}{1pt}
\savestack\trafficlight{%
\stackinset{c}{}{c}{}{%
\Shortstack{\textcolor{red}{$\bullet$} \textcolor{yellow}{$\bullet$}
\textcolor{green}{$\bullet$}}%
}{\textcolor{blue!30!gray}{\rule{1.55ex}{4.2ex}}}%
}
\begin{document}
This is a \trafficlight.
\end{document}
答案3
以下是一段简短的代码pstricks
:
\documentclass[x11names, border = 5pt]{standalone}
\usepackage{pstricks-add}
\usepackage{auto-pst-pdf}
\begin{document}
\psset{fillstyle = solid}\everypsbox{\bfseries\textbullet\hspace{0.6em}Score }
\begin{psmatrix}[emnode = p, rowsep = 0.4cm]%
[name = rlight] \\ [name = olight] \\ [name = glight]
\ncbox[fillstyle = solid, fillcolor = SteelBlue3, linearc = 0.3, nodesepA = 0.7cm, nodesepB = 0.45cm, boxsize = 0.5]{rlight}{glight}
\foreach \l/\colour in {rlight/red, olight/Orange1, glight/SpringGreen2} {\pscircle[fillcolor = \colour](\l){0.3cm}}
\nput{180}{rlight}{\makebox[8cm][l]{21--30: high anaphylactic risk (Step 3)}}
\nput{180}{olight}{\makebox[8cm][l]{11--20: medium anaphylactic risk (Step 2)}}
\nput{180}{glight}{\makebox[8cm][l]{1--10: low anaphylactic risk (Step 1B/1A)}}
\end{psmatrix}
\end{document}
答案4
\documentclass[pstricks,border=1cm,dvipsnames]{standalone}
\begin{document}
\begin{pspicture}[fillstyle=solid](5,5)
\psframe[fillcolor=NavyBlue,framearc=.2](2,5)
\pscircle[fillcolor=green](1,1){.5}\rput(3.5,1){Score 1--10}
\pscircle[fillcolor=yellow](1,2.5){.5}\rput(3.5,2.5){Score 11--20}
\pscircle[fillcolor=red](1,4){.5}\rput(3.5,4){Score 21--30}
\end{pspicture}
\end{document}
动画片
以防您需要动画但没有 Adobe Reader 窗口。
\documentclass[pstricks,border=1cm,dvipsnames]{standalone}
\usepackage{multido}
\begin{document}
\multido{\i=1+1}{3}{%
\begin{pspicture}[fillstyle=solid](5,5)
\psframe[fillcolor=NavyBlue,framearc=.2](2,5)
\ifnum\i=3\relax
\pscircle[fillcolor=green](1,1){.5}
\else
\pscircle[fillcolor=green!5](1,1){.5}
\fi
\ifnum\i=1\relax
\pscircle[fillcolor=yellow](1,2.5){.5}
\else
\pscircle[fillcolor=yellow!5](1,2.5){.5}
\fi
\ifnum\i=2\relax
\pscircle[fillcolor=red](1,4){.5}
\else
\pscircle[fillcolor=red!5](1,4){.5}
\fi
\rput[l](3,1){Score 1--10}
\rput[l](3,2.5){Score 11--20}
\rput[l](3,4){Score 21--30}
\end{pspicture}}
\end{document}