将 tikzpictures 放在一起

将 tikzpictures 放在一起

我希望此文档中的三个三角形居中且彼此等距。我该怎么做?抱歉格式不对,我是 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}

在此处输入图片描述

答案1

您可以将全部三个三角形组合到一个tikzpicture环境中,并将每个三角形放置在一个scope环境中,这样您就可以将其放置在所需的任何位置。

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

在此处输入图片描述

答案2

有几种方法可以做到这一点。这里我向你展示一种使用 的方法\hspace{\stretch{1}}

但首先,您的代码存在一些影响排版的问题:

  • LaTeX 将空白行设置为新行,就像相邻tikzpicture环境之间的行一样
  • 你的图片太宽,一行放不下

所以我确定了你的 3 张 tikzpictures 的范围并将它们缩进,即缩进到左侧。为了显示此布局效果,我在上方和下方放置了一些盲文以识别页边距。

如果你排版:

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

在这种情况下,LaTeX 会尝试以 2:1 的比例插入空格...如果行允许的话;否则它会断行。

结果

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

相关内容