我有以下代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds,snakes}
\begin{document}
\begin{tikzpicture} [thick, framed]
\filldraw[fill=green!20] (2.85,0) rectangle (5.7,1);
\draw (4.45,0)--(4.45,1) node[above]{$\textsc{M}$};
\draw (5.7,0.5)--(11,0.5);%vandret linie til max
\draw (2.85,0.5)--(1,0.5);%vandret linie til min
\draw (11,0.39)--(11,0.61);
\draw (1,0.39)--(1,0.61);
\draw (0,-1) -- (11,-1);
\draw[snake=ticks,segment length=1cm] (0,-1) -- (11,-1);
\end{tikzpicture}
\end{document}
我想要在箱线图下方的线上显示数字(像在坐标系中一样),该怎么做?
我对 LaTeX 还很陌生,所以尽可能了解基础知识 :-)
答案1
您可以使用\foreach
循环来放置包含刻度标签的节点。
请注意,该snakes
库已被弃用。相反,您应该使用库decorations.pathreplacing
。然后通过设置添加刻度decoration=ticks, decorate
。您可以使用将\draw
线和刻度的命令组合成一个命令postaction
。指定postaction
将使用参数中指定的选项第二次绘制路径postaction
。这样,如果您想更改轴的大小,只需更改一次坐标即可。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture} [thick, framed]
\filldraw[fill=green!20] (2.85,0) rectangle (5.7,1);
\draw (4.45,0)--(4.45,1) node[above]{$\textsc{M}$};
\draw (5.7,0.5)--(11,0.5);%vandret linie til max
\draw (2.85,0.5)--(1,0.5);%vandret linie til min
\draw (11,0.39)--(11,0.61);
\draw (1,0.39)--(1,0.61);
\draw [
postaction={
draw,
decoration=ticks,
segment length=1cm,
decorate,
}
] (0,-1) -- (11,-1);
\foreach \tick in {0,...,11}
\node at (\tick,-1) [below=1pt] {\tick};
\end{tikzpicture}
\end{document}