# Label and ticks using pgfplots

I am using pgfplots to plot simple functions. For example,

\begin{tikzpicture}
\begin{axis}[grid=major,xmin=0,xmax=1,ymin=0,ymax=0.5]
(0,0.2)
(0.5,0.2)
(1,0)
};
\end{axis}
\end{tikzpicture}


I want to add a letter, say "x", at the point 0.5 on the horizontal axis to make some emphasis. Anyone knows how to do this?

• Do you just want the letter "x", or do you also want to draw a vertical line or something like that? Should the letter be aligned like the tick numbers, or should it be inside the axis? – Jake Jun 22 '13 at 21:45
• @Jake I think it would be better to put the letter inside the axis, because sometimes this emphasis might coincide with the original labels. – Richie Jun 22 '13 at 22:38

You can use the extra ... options:

extra x ticks={0.5},
extra x tick labels={$x$},


## Notes:

• As per Qrrbrbirlbel's suggestion, the extra tick labels are now aligned with the other labels.
• As requested in the comments I have added multiple extra tick marks.

## Code:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=major,xmin=0,xmax=1,ymin=0,ymax=0.5,
extra x ticks={0.1,0.5,0.7},
extra x tick labels={$x$,$y$,$z$},
extra x tick style={%
text height=\heightof{0},% Align labels at baseline
color=red,
},
]

• Can we align the x to the baselines from the other ticks? extra x tick style={text height=\heightof{0}} is one way, but not very nice. – Qrrbrbirlbel Jun 22 '13 at 22:40
• @PeterGrill Thanks a lot. But if I want to add two or more labels, I tried that extra x ticks={0.1,0.5,0.7}, extra x tick labels={$x$,$y$,$z$} does not work. Do you know how to do this? – Richie Jun 22 '13 at 22:40
• @LeonMeier: No, it's a new syntax. It's explained in pages 937 and 938 from pgfmanual.pdf. height("0") gives you the height of whatever is inside quotes. Similar functions are depth and width. – Ignasi Mar 10 '17 at 8:04