# A strange contradiction

I am writing a book and I have a confused problem! When I run the code in a single file (1 page), the desired picture is obtained (fig 1). However, when it put in the main file, tikzpictures be in a column (fig 2). I want the pictures be in a row. Please help me!

\begin{center}‎‎
\begin{tikzpicture}[scale=‎1‎.‎0‎]
\draw [very thin,fill=‎lightgray‎‎‎] (‎0‎,0‎) rectangle (‎3‎‎,‎3‎‎);‎‎‎
\node at (‎1‎.5‎‎,‎1‎.‎5‎‎) {$‎A‎$} ;‎‎‎
\node at (‎3.‎3‎‎‎‎‎,‎1‎.‎5‎‎‎‎) {$=$};‎‎‎‎                   % the ‎label‎‎
\end{tikzpicture}
\begin{tikzpicture}‎‎[scale=‎1‎.‎0‎]
‎\fill[green!‎2‎0‎‎‎] (0,0)--(0,‎3‎)--(‎3‎,0)--cycle ; % the filled ‎triangle‎
‎\draw (0,0)--(0,‎3‎)--(‎3‎,‎3‎)--(‎3‎,0)--cycle ;    % the square‎
\draw (0,‎3‎)--(‎3‎,0) ;                         % the diagonal‎
\node at (0.5,0.5) {$L$} ;                   % the label
‎‎\end{tikzpicture}‎\quad‎
\begin{tikzpicture}[scale=‎1‎.‎0‎]
\fill[blue!‎2‎0‎] (‎3‎,‎3‎)--(0,‎3‎)--(‎3‎,0)--cycle ;
\draw (0,0)--(0,‎3‎)--(‎3‎,‎3‎)--(‎3‎,0)--cycle ;
\draw (0,‎3‎)--(‎3‎,0) ;
\node at (‎2‎.5,‎2‎.5) {$U$} ‎;‎
\end{tikzpicture}
\end{‎center}‎‎

• Why don't you just put all figures in one tikz block? – Levy Jul 12 '18 at 12:44
• How, in one block tikzpictures are coincide. – user108438 Jul 12 '18 at 12:47
• Apparently, the figures take so much space that two of them don't fit in the text width. – egreg Jul 12 '18 at 13:34

## 2 Answers

The other answer shows what to do, but I comment here on why the behaviour is not strange (and not related to any code you showed in the question) a tikzpicture is like \includegraphics or a minipage or the letter X : it has no positioning logic at all.

You have

\begin{center}
X X X
\end{center}


so whether the X here is literally X or whether it's a tikzpicture you have a centred paragraph with three items, each separated by a normal inter-word space.

This paragraph is subject to TeX's usual line breaking algorithm so may be broken into 1, 2 or 3 lines depending on the width of the text block at this point. In your first example the text block was wide enough for three in a row, but the second example your text block must have been too narrow to get even two on the same line so you get one per line and the two inter-word spaces would be discarded.

This way you can draw them in one tikzpicture.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[very thin,fill=lightgray] (0,0) rectangle (3,3);
\node at (1.5,1.5) {$A$} ;
\node at (3.3,1.5) {$=$};                   % the label
\begin{scope}[xshift=3.6cm]
\fill[green!20] (0,0)--(0,3)--(3,0)--cycle ; % the filled triangle
\draw (0,0)--(0,3)--(3,3)--(3,0)--cycle ;    % the square
\draw (0,3)--(3,0) ;                         % the diagonal
\node at (0.5,0.5) {$L$} ;                   % the label
\end{scope}
\begin{scope}[xshift=6.6cm+1em]
\fill[blue!20] (3,3)--(0,3)--(3,0)--cycle ;
\draw (0,0)--(0,3)--(3,3)--(3,0)--cycle ;
\draw (0,3)--(3,0) ;
\node at (2.5,2.5) {$U$} ;
\end{scope}
\end{tikzpicture}
\end{document} 