Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I often end up shifting labels on my TikZ/PGFplot graphs using, for example, xshift=1.0em, or yshift=1.0ex. Are these the correct units to be using to to the shifting? I don't think I should use absolute units as those won't adjust if the font sizes change similar to this question on Which measurement units should one use in LaTeX?.

Wondering if there special considerations that I should keep in mind since this is not related to ordinary text?

share|improve this question
    
What kinds of labels are you thinking about? For things like axis and tick labels, using different anchors might frequently be a better approach. As far as units go, ex and em seem to be good choices, however. –  Jake Jun 22 '11 at 0:30
    
I had originally intended the question for graph labels, or to highlight specific coordinates, but you bring up a good point about axis and tick labels. So once the anchor points are chosen, if they still need to be shifted slightly how should that be done? –  Peter Grill Jun 22 '11 at 2:40
add comment

2 Answers 2

up vote 4 down vote accepted

This is more typography than TeX.

  1. The "natural" unit here seems to be \baselineskip - the distance between two baselines.
  2. Line thickness also depends on the font used, but there is no relative unit associated with it.

Some explanation:

  1. The positions of the labels doesn't directly depend on the font size, but on the Leading. Thats because figures must have the same text spacing and color as the text. And it's possible to set one and the same font with different leadings. So, the "natural" width here seems to be \baselineskip - the distance between two baselines. That's for the vertical positioning. Horizontal positioning is the same, or has a quotient depending on the font proportions. As there are fonts from extra narrow to extra wide.
  2. The line width used in all kind of line art also depends on the font used. Usually it's related to the x line thickness near the point where the two lines cross each other. That's like the ex size is related to the x height. But, unfortunately there is no relative unit associated with that. For example, if Computer Modern (thin lines) is used, an than is switched to, say, Schoolbook (thick lines), then the line thickness on the graph must be increased to match the darker color of the new font used.
share|improve this answer
add comment

Sort of adding on to Karl Karlsson's excellent answer:

In some cases, you might want to use the line width of the current plot (not of the font) to shift a label. You can use \pgflinewidth for this. However, this only works if the node with the label is specified as part of the \addplot command, otherwise it will be set to the standard PGF line width.

Here's an example of where this might come in useful:

pgfplots with thick lines

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[no markers, ymin=0,ymax=5]
\addplot +[line width=0.5cm] {3} node [anchor=base east, text=black] {Text};
\addplot +[line width=0.5cm] {2} node [anchor=base east,text=black,yshift=0.5\pgflinewidth] {Test};

\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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