3

I'm trying to align the labels a and b under the x axis to the same baseline. The alignment is wrong on the left-hand side of the picture. It is correct on the right-hand side, but isn't there a simpler way to achieve this (that is, without finding a value for below= by trial and error)?

Left-hand side:

      \begin{tikzpicture}[scale=0.65]%
      \draw [<->] (7,0) node[below left]{$x$} -- (0,0) -- (0,7);
      \draw [thick] (0,0) -- (6.5,6.5);%
      \node [below] at (2,0) {$a$};%
      \node [below] at (5,0) {$b$};%
      \end{tikzpicture}%

Right-hand side:

      \begin{tikzpicture}[scale=0.65]%
      \draw [<->] (7,0) node[below left]{$x$} -- (0,0) -- (0,7);
      \draw [thick] (0,0) -- (6.5,6.5);%
      \node [below=2.735] at (2,0) {$a$};%
      \node [below] at (5,0) {$b$};%
      \end{tikzpicture}%

enter image description here

2

One way of doing this is to add a \vphantom{b} in the a node. This inserts a zero-width rule the height of b, so basically makes the height of the a node the same as the b node.

Another option is to place the node relative to the bottom of the b node. First give the b node a name/label (\node [below] (b) at (5,0) {$b$};), then place the second node with \node [above] at (b.south -| 2,0) {$a$};.

A third choice is to set the text height to be the height of a $b$. You can get that height width the \heightof macro, so set text height=\heightof{$b$}.

enter image description here

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.65]%
\draw [<->] (7,0) node[below left]{$x$} -- (0,0) -- (0,7);
\draw [thick] (0,0) -- (6.5,6.5);
\node [below] at (2,0) {$a\vphantom{b}$};
\node [above] at (b.south -| 3,0) {$a$};
\node [below] at (5,0) {$b$};
\node [below,text height=\heightof{$b$}] at (4,0) {$a$};
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.