I want to place a lot of pictures and plots in a long document. By now, I am using figure-environment with center-environment, but the tikz-axis-plots didn't align well with included eps-pictures or tikz-pictures. I read PGFplot to occupy full \linewidth, and aligned y=axis across tikzpicture and the pgfplot-Manual (regarding alignment), and found out, that I can use ylabel style={overlay} and yticklabel style={overlay}.

To be precise, the situation is better, but images are still not aligned well. I want the left and right border of the grid to be exacly above the other boxes. See my example for illustration.

Thanks in advance.

    \documentclass{scrartcl} % Dokumentenklasse
    \usepackage[decimalsymbol=comma]{siunitx} % SI-Einheiten einheitlich setzen

    \usepackage{pgfplots,pgfmath} % Import der Plots aus Matlab
    \usepackage{tikz} % Import der Plots aus Matlab
    \usetikzlibrary{plotmarks} % Import der Plots aus Matlab
    \newlength\fheight % Plots aus Matlab immer gleich gross
    \newlength\fwidth % Plots aus Matlab immer gleich gross
    \setlength\fheight{6cm} % Plots aus Matlab immer gleich gross
    \setlength\fwidth{8cm} % Plots aus Matlab immer gleich gross
    \pgfplotsset{ % Komma statt Punkt als Dezimaltrennzeichen
      x tick label style={/pgf/number format/use comma},
      y tick label style={/pgf/number format/use comma}}


    scale only axis,
    xmin=0, xmax=15,
    ymin=0, ymax=200,
    ylabel style={overlay},
    yticklabel style={overlay},

    \addplot [
    only marks,
    mark options={solid,fill=green}
      \caption{Axis example}

    \begin{tikzpicture}[even odd rule,rounded corners=2pt,x=10pt,y=10pt]
    \filldraw[fill=green] (0,0) rectangle (\fwidth,\fheight);
      \caption{Size of the pictures}


What you are seeing the bounding box of the leftmost x (!) tick label: it shifts your axis to the right.

A possible solution is to use xticklabel style={overlay} as well.

However, my advice is to use

\begin{tikzpicture}[trim axis left, trim axis right]

which configures TikZ to 1. assume a following axis and 2. to skip everything left of that axis and right of that axis when it computes bounding boxes.

This approach is fairly new, and recent versions of pgfplots provide more documentation. The approach will automatically solve this kind of alignment problems (it even works together with image externalization).

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.