# pgfplots boundingbox is offset

So I got this code to visualize the bounding boxes in my tex:

\fbox{
\begin{minipage}{0.5\columnwidth}
\centering
\fbox{\begin{tikzpicture}[declare function={unipdf(\x,\xl,\xu)= (\x>\xl)*(\x<\xu)*1/(\xu-\xl);}]
\begin{axis}[
samples=100,
const plot mark mid,
scaled ticks = false,
ymin=0,ymax=0.5,
xmin=-3,xmax=3,
xtick={-2,2},
xticklabels={-$\frac{LSB}{2}$,$\frac{LSB}{2}$}],
ytick={0.25},
yticklabels={$\frac{1}{LSB}$}]
\end{axis}
\end{tikzpicture}}
\caption{$dt=0.1$}
\label{fig:prob1_6_2}
\end{minipage}%
}


Which results in this:

Of course, fbox could be wrong. Sadly the borders confirm what I suspected: The bounding boxes have a weird offset. So having the minipage at 0.5\linewidth lets the plots overlap.

I would be glad if someone points out to me where my missconception lies since I cannot find a particular reason for this.

• You haven't fixed the bug in your code that I mentioned in your previous question ... – Torbjørn T. Feb 23 '17 at 10:27
• No indeed, in this picture I didn't, you are absolutely right. It has no influence tho (I can show you if you like so). – Yatekii Feb 23 '17 at 10:30
• Yes it does have an influence on the result (though I'm not entirely sure why), try the code in my answer with and without that extra ]. – Torbjørn T. Feb 23 '17 at 10:33
• thank you very much kind sir! Why I said it doesn't matter is because I already corrected it and just posted the answer before (don't ask why). But it didn't change anything. The width attribute on the axis fixed it tho! – Yatekii Feb 23 '17 at 10:41

There are two problems here:

1. pgfplots yticklabels wont work

2. The default width of an axis is 240pt, but with a standard article document, 0.5\columnwidth is 172.5pt. Hence, the axis is wider than the minipage, and thus sticks out on the right side. Add e.g. width=\textwidth to the axis options.

Complete code:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\the\columnwidth
\begin{figure}
\fbox{%
\begin{minipage}{0.5\columnwidth}
\centering
\fbox{\begin{tikzpicture}[declare function={unipdf(\x,\xl,\xu)= (\x>\xl)*(\x<\xu)*1/(\xu-\xl);}]
\begin{axis}[
width=\textwidth,
samples=100,
const plot mark mid,
scaled ticks = false,
ymin=0,ymax=0.5,
xmin=-3,xmax=3,
xtick={-2,2},
xticklabels={-$\frac{LSB}{2}$,$\frac{LSB}{2}$},
ytick={0.25},
yticklabels={$\frac{1}{LSB}$}]
\caption{$dt=0.1$}