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).

enter image description here However, when it put in the main file, tikzpictures be in a column (fig 2). enter image description here

I want the pictures be in a row. Please help me!

    \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‎‎
    ‎\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
   \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$} ‎;‎
  • 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
  • 1
    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

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


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.

    \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
        \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
        \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$} ;

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.