tikzpicture alignment and centering
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}
This is another method.
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=2cm,showframe]{geometry}
%------------------------------------------
\begin{document}
\begingroup
\centering
\begin{minipage}[c]{.5\textwidth}
\flushright
%------------------------------------------
\begin{tikzpicture}
\draw[line width=30pt] (0,0) -- (7,0);
\end{tikzpicture}\\
%------------------------------------------
\begin{tikzpicture}
\draw[line width=30pt] (0,0) -- (7,0);
\draw[line width=20pt] (-0.4, 0) -- (-0.1, 0);
\end{tikzpicture}\\
%------------------------------------------
\begin{tikzpicture}
\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{tikzpicture}%
\draw[line width=30pt] (0,0) -- (7,0);
\end{tikzpicture}\\%
%------------------------------------------
\begin{tikzpicture}%
\draw[line width=30pt] (0,0) -- (7,0);
\draw[line width=20pt] (-0.4, 0) -- (-0.1, 0);
\end{tikzpicture}\\%
%------------------------------------------
\begin{tikzpicture}%
\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{minipage}
\vfil
%%%====================================
\rotatebox{90}{
\begin{minipage}[c]{.5\textwidth}
\flushright
%------------------------------------------
\begin{tikzpicture}
\draw[line width=30pt] (0,0) -- (7,0);
\end{tikzpicture}\\
%------------------------------------------
\begin{tikzpicture}
\draw[line width=30pt] (0,0) -- (7,0);
\draw[line width=20pt] (-0.4, 0) -- (-0.1, 0);
\end{tikzpicture}\\
%------------------------------------------
\begin{tikzpicture}
\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{tikzpicture}%
\draw[line width=30pt] (0,0) -- (7,0);
\end{tikzpicture}\\%
%------------------------------------------
\begin{tikzpicture}%
\draw[line width=30pt] (0,0) -- (7,0);
\draw[line width=20pt] (-0.4, 0) -- (-0.1, 0);
\end{tikzpicture}\\%
%------------------------------------------
\begin{tikzpicture}%
\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{minipage}}\par
\endgroup
%------------------------------------------
\end{document}
The length of the code can be reduced by making use of \savebox
since they are same figures with a different rotation.