我有这个代码:
\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}