![将标签与节点 [下方] 一起放置在轴上](https://linux22.com/image/462642/%E5%B0%86%E6%A0%87%E7%AD%BE%E4%B8%8E%E8%8A%82%E7%82%B9%20%5B%E4%B8%8B%E6%96%B9%5D%20%E4%B8%80%E8%B5%B7%E6%94%BE%E7%BD%AE%E5%9C%A8%E8%BD%B4%E4%B8%8A.png)
我有这个代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.6,yscale=2,xscale=1.5]
\draw[help lines, color=gray!30, dashed] (0, 0) grid (2.5,1.5);
\draw[->] (0,0)--(2.5,0) node[below]{$x$};
\draw[->] (0,0)--(0,1) node[above]{};
\node[left] (O) at (0,0) {$0$};
\node[left] (1) at (0,1) {$1$};
\coordinate (a) at (1,0);
\coordinate (b) at (1.5,1);
%
\draw[ultra thick] (0,0)--(a) node {};
\draw[ultra thick] (a)--(b) node {};
\draw[ultra thick] (b)--(2.5,1) node {};
\draw[dashed] (1.5,0) -- (1.5,1) node {};
\node[below] () at (1,0) {$a$};
\node[below] () at (1.5,0) {$b$};
\end{tikzpicture}
\end{document}
标签a
和b
x 轴上的标签未正确对齐(垂直)。
有什么方法可以使它们对齐吗?
答案1
我完全同意 Qrrbrbirlbel 的评论。但是这里还有另一个选项:a \strut
,它创建具有所需高度和深度但没有水平空间的垂直空间。
也就是说,我稍微减少了你的代码:
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.6,yscale=2,xscale=1.5]
\coordinate (a) at (1,0);
\coordinate (b) at (1.5,1);
\draw[help lines, color=gray!30, dashed] (0,0) grid (2.5,1.5);
\draw[->] (0,1) node[left]{$1$} -- (0,0) node[left] {$0$} -- (a) node[below]{\strut$a$} -- (2.5,0) node[below]{\strut$x$};
\draw[ultra thick] (0,0) -- (a) -- (b) -- (2.5,1);
\draw[dashed] (1.5,0) node[below] {\strut$b$} -- (b);
\end{tikzpicture}
\end{document}