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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to include a figure that I made in MATLAB. I want to change the font using \psfrag, however there seems to be a problem when scaling the figure down. It keeps the font the same size as the text, which is fine, but the tick labels keep their position (they are overlapping the axes!), which looks bad. See the figure below. MWE follows below.


\psfrag{0}{$ 0 $}
\psfrag{5}{$ 5 $}
\psfrag{10}{$ 10 $}
\psfrag{15}{$ 15 $}
\psfrag{20}{$ 20 $}
\psfrag{25}{$ 25 $}
\psfrag{30}{$ 30 $}
\psfrag{358}{$ 358 $}
\psfrag{360}{$ 360 $}
\psfrag{362}{$ 362 $}
\psfrag{364}{$ 364 $}
\psfrag{366}{$ 366 $}
\psfrag{368}{$ 368 $}
\psfrag{370}{$ 370 $}
\psfrag{xtitle}{$ d_{c}\, \mathrm{[\mu m]} $}
\psfrag{ytitle}{$ t_{i}\, \mathrm{[nm]} $}
\caption{Insert caption}
\label{fig: layer thickness}

The font of the tick labels are changed using <code>\psfrag</code>, but the positioning is bad.

share|improve this question
This is normal, you are asking it to insert some text, psfrag has no idea which size to use, it can only tell TeX where to place it. Try adding, say, \footnotesize just after \begin{figure}. BTW: centering is not an environment, and the \par is unnessary. – daleif Jan 11 '13 at 11:51
I think I need to use another solution than psfrag then. Because no matter the size of the numbers, it's the positioning that I want to change. I want to keep more space from the axes. Any ideas? – Carsten Gade Jan 11 '13 at 12:44
@CarstenGade Did you have a look at matlabfrag to pdf ?. Read the documentation of matlabfrag line 223. Of course there are many options Best way to include Matlab figure – texenthusiast Jan 11 '13 at 19:03
@texenthusiast Thanks for the tip about matlabfrag - that did it for me! – Carsten Gade Jan 19 '13 at 15:43

You can adjust the horizontal position using \rlap and \kern, and the vertical position using \strut, \smash and \raisebox. I cannot show it on your example, but the following might give a hint:







Meaning of the macros:

  • \rlap{#1} typesets #1 on the right from the current position, occupying no space. There are macros \llap and \clap as well.
  • \kern#1\relax inserts a space of size #1, in this case horizontal (\rlap's content is in horizontal mode) and negative.
  • \strut typesets an invisible box of zero width and height+depth of a "maximal size of a letter without accents".
  • \smash{#1} typesets #1 as if it had no height at all. We use \strut\smash to ensure that \raisebox has the desired effect.
  • \raisebox{#1}{#2} takes #2 and moves it vertically by #1.

Now, you should be able to write something like \psfrag{358}{\ytick{$358$}}, and if you play with the value -0.2em for a while, you get the desired result. In a similar way you can move the axis label to the left (which means vertically since it's 90 degrees rotated).

share|improve this answer

Check out the psfrag documentation, section 5 "Commands and Environments": Using optional arguments, you can control the horizontal and vertical alignment of the replacement text with respect to the original object. For example, in my own documents I commonly use something like this:

\psfrag{ylabel}[cc][cc][0.85]{Message error rate}
\psfrag{LegendLine1}[lc][lc][0.85]{My Stuff}

I don't know if I remember it correctly. In doubt, check out the psfrag doc. But the first argument should be the latex reference point, the second the postscript reference point and the third the scale (so you can additionally scale the font size, which maybe you don't need, but I usually do). So, the first line above should align the horizontal and vertical center of the replacement text ("Message error rate") with the horizontal and vertical center of the placeholder I entered in Matlab ("ylabel"). The second line aligns the replacement centered vertically, but to the left horizontally, which is typically what you want in the case of a legend in your figure.

share|improve this answer
Welcome to TeX.SX! – Claudio Fiandrino Oct 29 '13 at 13:43

Your Answer


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.