For getting the horizontal alignment right, you could supply the trim left
option to the tikzpicture
s, which sets the bounding box so it starts at x=0
. There's no option like that for the vertical alignment, however, so in that case you'll have to make sure the bounding boxes between the pictures match by setting them manually using \pgfresetboundingbox
and then issuing a \path
command that has the right dimensions.
You can automate this by defining a style like
master/.style={
execute at end picture={
\coordinate (lower right) at (current bounding box.south east);
\coordinate (upper left) at (current bounding box.north west);
}
}
which you supply to the first picture of a group to save the necessary bounding box information, and
slave/.style={
execute at end picture={
\pgfresetboundingbox
\path (upper left) rectangle (lower right);
}
}
which you supply to the other pictures in the group to set their bounding box to be equal to that of the first picture.
You have to be a bit careful with manually adjusted bounding boxes, as the pictures could protrude into the page margins or into the surrounding text.
\documentclass[10pt]{book}
\usepackage{tikz}
\tikzset{
master/.style={
execute at end picture={
\coordinate (lower right) at (current bounding box.south east);
\coordinate (upper left) at (current bounding box.north west);
}
},
slave/.style={
execute at end picture={
\pgfresetboundingbox
\path (upper left) rectangle (lower right);
}
}
}
\begin{document}
\begin{tikzpicture}[master]
\draw[line width=30pt] (0,0) -- (7,0);
\end{tikzpicture}
\begin{tikzpicture}[slave]
\draw[line width=30pt] (0,0) -- (7,0);
\draw[line width=20pt] (-0.4, 0) -- (-0.1, 0);
\end{tikzpicture}
\begin{tikzpicture}[slave]
\draw[line width=30pt] (0,0) -- (7,0);
\draw[line width=20pt] (-0.4, 0) -- (-0.1, 0);
\draw[line width=20pt] (-0.8, 0) -- (-0.5, 0);
\end{tikzpicture}
\begin{center}%
\begin{tikzpicture}[master]%
\draw[line width=30pt] (0,0) -- (7,0);
\end{tikzpicture}%
\end{center}%
\begin{center}%
\begin{tikzpicture}[slave]%
\draw[line width=30pt] (0,0) -- (7,0);
\draw[line width=20pt] (-0.4, 0) -- (-0.1, 0);
\end{tikzpicture}%
\end{center}%
\begin{center}%
\begin{tikzpicture}[slave]%
\draw[line width=30pt] (0,0) -- (7,0);
\draw[line width=20pt] (-0.4, 0) -- (-0.1, 0);
\draw[line width=20pt] (-0.8, 0) -- (-0.5, 0);
\end{tikzpicture}%
\end{center}%
\begin{tikzpicture}[master]%
\draw[line width=30pt] (0,0) -- (0,7);
\end{tikzpicture}%
\hspace{1em}
\begin{tikzpicture}[slave]%
\draw[line width=30pt] (0,0) -- (0,7);
\draw[line width=20pt] (0,-0.4) -- (0,-0.1);
\end{tikzpicture}%
\hspace{1em}
\begin{tikzpicture}[slave]%
\draw[line width=30pt] (0,0) -- (0,7);
\draw[line width=20pt] (0,-0.4) -- (0,-0.1);
\draw[line width=20pt] (0,-0.8) -- (0,-0.5);
\end{tikzpicture}%
\begin{center}%
\begin{tikzpicture}[master]%
\draw[line width=30pt] (0,0) -- (0,7);
\end{tikzpicture}%
\hspace{1em}
\begin{tikzpicture}[slave]%
\draw[line width=30pt] (0,0) -- (0,7);
\draw[line width=20pt] (0,-0.4) -- (0,-0.1);
\end{tikzpicture}%
\hspace{1em}
\begin{tikzpicture}[slave]%
\draw[line width=30pt] (0,0) -- (0,7);
\draw[line width=20pt] (0,-0.4) -- (0,-0.1);
\draw[line width=20pt] (0,-0.8) -- (0,-0.5);
\end{tikzpicture}%
\end{center}%
\end{document}
You could transform your data to milliseconds by using x filter/.code=\pgfmathparse{#1*1000}
, but a more elegant approach would be to use the units
library, which is loaded using \pgfplotslibrary{units}
in the preamble. You can then set x unit=s
to specify that the data is in seconds, set change x base=true
to allow pgfplots to transform the data, and then set x SI prefix=milli
to change the units to milliseconds.
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=tijd,
ycomb, ymin=0, ymax=4, xmin=0.0248, xmax=0.0255,
enlarge y limits=false,
width=15cm, height=5cm,
tick align = outside,
grid = major,
%scaled x ticks = false,
yticklabels={X, 0, settings, macroblock, picture},
x unit=s,
change x base=true,
x SI prefix=milli
]
\addplot +[mark=none, ultra thick] table {
0.0249 2
0.0251 1
0.0254 1
};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
Using
showframe
shows the issue -- the margins are not same on the left and right side. Usinggeometry
this can be repaired, the given values are just guesses.I did not address the axis scaling 'sub'question