I have several very similar images except some have some extra graphics that enlarge them slightly. This causes some pictures to be offset and not aligned visually when it's clear they should be.
How can I align several tikzpicture
s along the the same origin they were created and center vertically and horizontally properly?
First, I want to align the 3 large boxes regardless of the what the small boxes are doing
Second, I want to be able to center them all without adding additional spaces the
\begin{center}
seems to doThird, I want to be able to reproduce the exact same results but everything in landscape mode without using the landscape package if possible. (as you can see, the problem is that TeX is putting one rectangle at a time which is not what I want)
The methods should be easy and quick. I have many rectangles stacked and some need to be grouped arbitrarily. What these means is I want the methods to sort of be "smart" in that they can figure out themselves so I don't have to go change a lot of stuff each time I have to change the grouping. Basically I would like the first rectangle on the page to define the alignment location and the others on the same page to use it unless I tell them not to.
I've tried creating a custom bounding box as shown in How does TiKZ calculate positioning of picture on page? but it didn't do anything unless I make it too large which then causes other problems. (I can end up doing the alignment but it seems more complex than necessary)
\documentclass[10pt]{book}
\usepackage{tikz}
\begin{document}
\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{center}%
\begin{tikzpicture}%
\draw[line width=30pt] (0,0) -- (7,0);
\end{tikzpicture}%
\end{center}%
\begin{center}%
\begin{tikzpicture}%
\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}%
\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}%
\draw[line width=30pt] (0,0) -- (0,7);
\end{tikzpicture}%
\begin{tikzpicture}%
\draw[line width=30pt] (0,0) -- (0,7);
\draw[line width=20pt] (0,-0.4) -- (0,-0.1);
\end{tikzpicture}%
\begin{tikzpicture}%
\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}%
\draw[line width=30pt] (0,0) -- (0,7);
\end{tikzpicture}%
\end{center}
\begin{center}%
\begin{tikzpicture}%
\draw[line width=30pt] (0,0) -- (0,7);
\draw[line width=20pt] (0,-0.4) -- (0,-0.1);
\end{tikzpicture}%
\end{center}%
\begin{center}%
\begin{tikzpicture}%
\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}
center
environment is more for text paragraphs and will add the vertical space because of this. The\centering
macro should be used for figure and such because of this. It can be grouped using\begingroup
..\engroup
if required. A paragraph break (\par
) before the\engroup
might also be a good idea. An alternative is\adjustbox{center=<width>}{..}
(adjustbox
package), which centers the content by adding white space to the left and right. The<width>
value is optional and default to the text width.tikzpicture
s by placing them into\node
s of a parenttikzpicture
which can then be aligned using the usual TikZ settings. Alternatively enlarge the bounding box of every picture manually so that it is always identical. A technique like this is used in Centering a TikZ picture around an area BTW, (semi-)automatic placement and alignment is rather difficult to achieve with multiple pictures.