3

Possible Duplicate:
pgfplots: how can I scale to text width?

Without using such command as trim axis=left or scale only axis, I would expect the following plots to be contained in the text area :

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
  \centering
  \begin{tikzpicture}
    \begin{axis}[%
      width=\textwidth,
      height=0.3\textheight,
      axis on top,
      ytick=data,
      yticklabels={\dots ,Happens ,Nothing ,Xyzzzzzzzzzzzzzy !}]
      \pgfplotstableread{
        1 4   
        2 4.2 
        3 3.1 
        4 2.5 
      }\table
      \addplot[xbar] table[x index=1, y index=0]{\table};
    \end{axis}
  \end{tikzpicture} 
\end{figure}

Some text. Some text. Some text. Some text. Some text. Some text. Some
text. Some text. Some text. Some text. Some text. Some text. Some
text. Some text. Some text. Some text. Some text. Some text. Some
text. Some text. Some text. Some text. Some text. Some text. Some
text. Some text. Some text.
\end{document}

However, it overlaps with the margins :

enter image description here

Do you know what am I doing wrong?

Some elements of answer: I was wrongly supposing that the width of the labels was measured. Some techniques have already been proposed to deal with this issue in this question, as pointed out by Jake in the comments.

M. Toya
  • 3,227
  • 5
    This happens because PGFPlots just assumes the tick labels to take up a certain amount of space instead of using the actual dimensions. Take a look at pgfplots: how can I scale to text width?, especially MMM's answer, which provides a clever way to fix this. – Jake Sep 07 '12 at 11:58
  • 1
    Could you clarify if the other question is a duplicate of this one? If it isn't could you specify what particular aspect you're looking for? – Jake Sep 07 '12 at 12:59
  • I could not make MMM's solution work in my case but it might indeed be a duplicate. Maybe this alternative formulation could help people getting to the question you mentioned ? I did not find it before asking.

    I do not really know what I am supposed to do in this situation.

    – M. Toya Sep 07 '12 at 15:21

0 Answers0