4

I want the three triangles in this document to be centered and equidistant from each other. How would I do that? Sorry about the formatting, I'm new in this side of StackExchange.

\documentclass{article}
\usepackage{tkz-euclide}
    \begin{document}
   % \usepackage{tkz-euclide}

    %triangle 1

    \begin{tikzpicture}[scale=1.0]
    %define points A,B,C
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDefPoint(3,2){C}
    
    %draw triangleABC
    \tkzDrawPolygon[thick](A,B,C)
    
    %marking right angles 
    \tkzMarkRightAngle(A,B,C)    
    
    %marking the angles
    
    \tkzLabelAngle[pos=1](B,A,C){$\theta$}
        
    %label the sides
    \tkzLabelLine[pos=0.5,above, ](A,C){$a$}
    \tkzLabelLine[pos=0.5,below, ](A,B){$\sqrt{a^2-x^2}$}
    \tkzLabelLine[pos=0.5,right](B,C){$x$}
    
    \end{tikzpicture}

    %triangle 2

    \begin{tikzpicture}[scale=1.0]
    %define points A,B,C
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDefPoint(3,2){C}
    
    %draw triangleABC
    \tkzDrawPolygon[thick](A,B,C)
    
    %marking right angles 
    \tkzMarkRightAngle(A,B,C)    
    
    %marking the angles
    
    \tkzLabelAngle[pos=1](B,A,C){$\theta$}
        
    %label the sides
    \tkzLabelLine[pos=0.5,above, pos=.6, left,](A,C){$\sqrt{x^2+a^2}$}
    \tkzLabelLine[pos=0.5,below, ](A,B){$a$}
    \tkzLabelLine[pos=0.5,right](B,C){$x$}
    
    \end{tikzpicture}

    %triangle 3

    \begin{tikzpicture}[scale=1.0]
    %define points A,B,C
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDefPoint(3,2){C}
    
    %draw triangleABC
    \tkzDrawPolygon[thick](A,B,C)
    
    %marking right angles 
    \tkzMarkRightAngle(A,B,C)    
    
    %marking the angles
    
    \tkzLabelAngle[pos=1](B,A,C){$\theta$}
        
    %label the sides
    \tkzLabelLine[pos=0.5,above, ](A,C){$x$}
    \tkzLabelLine[pos=0.5,below, ](A,B){$a$}
    \tkzLabelLine[pos=0.5,right](B,C){$\sqrt{x^2-a^2}$}
    
    \end{tikzpicture}
    \end{document}

enter image description here

2
  • Get rid of the blank lines outside the tikzpictures. Blank lines start new paragrahs. (TikZ has its own parser.) You can use \hfil or \hfill instead. Apr 12 at 12:32
  • As pointed out John Kormylo with \fill you can see egreg's answer to this post tex.stackexchange.com/questions/707806/…
    – pascal974
    Apr 12 at 13:30

2 Answers 2

5

You can combine all three triangles in a single tikzpicture environment and place each one in a scope environment, which allows you to place it wherever you want.

\documentclass{article}
\usepackage{tkz-euclide}
    \begin{document}
   % \usepackage{tkz-euclide}

    %triangle 1

    \begin{tikzpicture}[scale=1.0]
    %define points A,B,C
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDefPoint(3,2){C}
    
    %draw triangleABC
    \tkzDrawPolygon[thick](A,B,C)
    
    %marking right angles 
    \tkzMarkRightAngle(A,B,C)    
    
    %marking the angles
    
    \tkzLabelAngle[pos=1](B,A,C){$\theta$}
        
    %label the sides
    \tkzLabelLine[pos=0.5,above, ](A,C){$a$}
    \tkzLabelLine[pos=0.5,below, ](A,B){$\sqrt{a^2-x^2}$}
    \tkzLabelLine[pos=0.5,right](B,C){$x$}
    
\begin{scope}[xshift=4cm]
    %define points A,B,C
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDefPoint(3,2){C}
    
    %draw triangleABC
    \tkzDrawPolygon[thick](A,B,C)
    
    %marking right angles 
    \tkzMarkRightAngle(A,B,C)    
    
    %marking the angles
    
    \tkzLabelAngle[pos=1](B,A,C){$\theta$}
        
    %label the sides
    \tkzLabelLine[pos=0.5,above, pos=.6, left,](A,C){$\sqrt{x^2+a^2}$}
    \tkzLabelLine[pos=0.5,below, ](A,B){$a$}
    \tkzLabelLine[pos=0.5,right](B,C){$x$}
\end{scope}    
    
\begin{scope}[xshift=8cm]
    %define points A,B,C
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDefPoint(3,2){C}
    
    %draw triangleABC
    \tkzDrawPolygon[thick](A,B,C)
    
    %marking right angles 
    \tkzMarkRightAngle(A,B,C)    
    
    %marking the angles
    
    \tkzLabelAngle[pos=1](B,A,C){$\theta$}
        
    %label the sides
    \tkzLabelLine[pos=0.5,above, ](A,C){$x$}
    \tkzLabelLine[pos=0.5,below, ](A,B){$a$}
    \tkzLabelLine[pos=0.5,right](B,C){$\sqrt{x^2-a^2}$}
\end{scope}   
    \end{tikzpicture}
    \end{document}

enter image description here

1

There are several ways to do it. Here I show you one using \hspace{\stretch{1}}.

But first, there are some problems with your code affecting typesetting:

  • LaTeX type-sets a blank line as a new line, like you have between adjacent tikzpicture environments
  • your pictures are too wide to fit into one line

So I scoped your 3 tikzpictures AND indented them out, i.e. to the left. To show this layout effect I put some blindtext above and below to recognize the page margins.

If you'd typeset:

...
\hspace{\stretch{2}} ... \hspace{\stretch{1}}
...

LaTeX would try inserting space in the ratio of 2:1 in this case ... if the line allows it; else it breaks the line.

result

\documentclass{article}
\usepackage{tkz-euclide}
\usepackage{lipsum}

\begin{document}

\lipsum[5]

{\parindent-2cm
 % ~~~ triangle 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 \begin{tikzpicture}[scale=1.0]
    %define points A,B,C
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDefPoint(3,2){C}
    
    %draw triangleABC
    \tkzDrawPolygon[thick](A,B,C)
    
    %marking right angles 
    \tkzMarkRightAngle(A,B,C)    
    
    %marking the angles
    
    \tkzLabelAngle[pos=1](B,A,C){$\theta$}
        
    %label the sides
    \tkzLabelLine[pos=0.5,above, ](A,C){$a$}
    \tkzLabelLine[pos=0.5,below, ](A,B){$\sqrt{a^2-x^2}$}
    \tkzLabelLine[pos=0.5,right](B,C){$x$}
    
 \end{tikzpicture}
  \hspace{\stretch{1}}
 % ~~~ triangle 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~
  \begin{tikzpicture}[scale=1.0]
    %define points A,B,C
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDefPoint(3,2){C}
    
    %draw triangleABC
    \tkzDrawPolygon[thick](A,B,C)
    
    %marking right angles 
    \tkzMarkRightAngle(A,B,C)    
    
    %marking the angles
    
    \tkzLabelAngle[pos=1](B,A,C){$\theta$}
        
    %label the sides
    \tkzLabelLine[pos=0.5,above, pos=.6, left,](A,C){$\sqrt{x^2+a^2}$}
    \tkzLabelLine[pos=0.5,below, ](A,B){$a$}
    \tkzLabelLine[pos=0.5,right](B,C){$x$}
    
 \end{tikzpicture}
 \hspace{\stretch{1}}
 % ~~~ triangle 3 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 \begin{tikzpicture}[scale=1.0]
    %define points A,B,C
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDefPoint(3,2){C}
    
    %draw triangleABC
    \tkzDrawPolygon[thick](A,B,C)
    
    %marking right angles 
    \tkzMarkRightAngle(A,B,C)    
    
    %marking the angles
    
    \tkzLabelAngle[pos=1](B,A,C){$\theta$}
        
    %label the sides
    \tkzLabelLine[pos=0.5,above, ](A,C){$x$}
    \tkzLabelLine[pos=0.5,below, ](A,B){$a$}
    \tkzLabelLine[pos=0.5,right](B,C){$\sqrt{x^2-a^2}$}
 \end{tikzpicture}
 } % ending scope of \parindent
 
 \lipsum[5]

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .