tkz-euclide 命令更改 tikzfigure 的位置 - 需要它停止

tkz-euclide 命令更改 tikzfigure 的位置 - 需要它停止

我很少在 ChatGPT 和 Google 上尋找問題的解決方案,但根本找不到任何提及該問題的情況。也許我只是不擅長搜尋。

在下面的程式碼中,我有四個小頁面顯示不同類型的三角形。在等腰三角形和等邊三角形(但不包括不等邊三角形)中使用 tkx-euclide 指令。它將這兩個圖居中並垂直移動它們。我不希望它們居中,也不希望它們垂直移動。所以我需要一個解決問題的方法。我認為 \tkzLabelAngle 命令導致了問題,但我需要一種方法來使用該命令而不會出現定位問題。

謝謝

\begin{minipage}[t]{0.475\linewidth}
    \textsf{\textbf{Scalene Triangle}}
    \newline\newline
        \begin{tikzpicture}
            \draw (0,0) -- (1,2) -- (3,1.75) -- (0,0);
        \end{tikzpicture}
\end{minipage}
\begin{minipage}[t]{0.475\linewidth}
    \textsf{\textbf{Isosceles Triangle}}
    \newline\newline
        \begin{tikzpicture}
            \coordinate (A) at (0,0);
            \coordinate (B) at (4,0);
            \coordinate (C) at (2,1.5);
            \draw (0,0) -- (4,0) -- (2,1.5) -- (0,0);
            \tkzMarkSegment[color=black,pos=.5,mark=|](A,C)
            \tkzMarkSegment[color=black,pos=.5,mark=|](B,C)
            \tkzLabelAngle[pos=-0.33](C,A,B){$\circ$}
            \tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
        \end{tikzpicture}
\end{minipage}
\newline\newline
\begin{minipage}[t]{0.475\linewidth}
    \textsf{\textbf{Equilateral Triangle}}
    \newline\newline
        \begin{tikzpicture}
            \coordinate (A) at (0,0);
            \coordinate (B) at (3,0);
            \coordinate (C) at (1.5,{1.5*sqrt(3)});
            
            \draw (A) -- (B) -- (C) -- cycle;
            \tkzLabelAngle[pos=-0.33](C,A,B){$\circ$}
            \tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
            \tkzLabelAngle[pos=-0.33](B,C,A){$\circ$}
        \end{tikzpicture}
\end{minipage}
\begin{minipage}[t]{0.475\linewidth}
    \textsf{\textbf{Right Triangle}}
    \newline\newline
        \begin{tikzpicture}
            
        \end{tikzpicture}
\end{minipage}

答案1

最好將它們全部繪製在一張不同的 tikz 圖片中,並以不同的值scope定位它們。shift我相信負pos鍵值可能會導致更大的邊界框。如果可能的話最好使用正值。

\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\draw (0,0) -- (1,2) -- (3,1.75) -- cycle;
\node at (1.5,2) [above=0.5cm] {\textsf{\textbf{Scalene Triangle}}};
\end{scope}
\begin{scope}[xshift=6cm]
\coordinate (A) at (0,0);
\coordinate (B) at (4,0);
\coordinate (C) at (2,1.5);
\draw (0,0) -- (4,0) -- (2,1.5) -- cycle;
\tkzMarkSegment[color=black,pos=.5,mark=|](A,C)
\tkzMarkSegment[color=black,pos=.5,mark=|](B,C)
\tkzLabelAngle[pos=-0.33](C,A,B){$\circ$}
\tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
\node at (C)  [above=1cm] {\textsf{\textbf{Isosceles Triangle}}};
\end{scope}
\begin{scope}[yshift=-4cm]
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (1.5,{1.5*sqrt(3)});
\draw (A) -- (B) -- (C) -- cycle;
\tkzLabelAngle[pos=0.33](B,A,C){$\circ$}
\tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
\tkzLabelAngle[pos=0.33](A,C,B){$\circ$}
\node at (C) [above=0.5cm] {\textsf{\textbf{Equilateral Triangle}}};
\end{scope}
\begin{scope}[shift={(6.5cm,-4cm)}]
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (3,{1.5*sqrt(3)});
\draw (A) -- (B) -- (C) -- cycle;
\node at (1.5,{1.5*sqrt(3)}) [above=0.5cm] {\textsf{\textbf{Right Triangle}}};
\end{scope}
\end{tikzpicture}
\end{document}

在此輸入影像描述

################################################### ## ############################

這是一個範例,顯示負值pos放大邊界框。相同的繪圖但負值pos使左下角和頂角具有更大的邊界框。

\documentclass{report}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (1.5,{1.5*sqrt(3)});
\draw (A) -- (B) -- (C) -- cycle;
\tkzLabelAngle[pos=0.33](B,A,C){$\circ$}
\tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
\tkzLabelAngle[pos=0.33](A,C,B){$\circ$}
\draw (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}

\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (1.5,{1.5*sqrt(3)});
\draw (A) -- (B) -- (C) -- cycle;
\tkzLabelAngle[pos=-0.33](C,A,B){$\circ$}
\tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
\tkzLabelAngle[pos=-0.33](B,C,A){$\circ$}
\draw (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
\end{document}

在此輸入影像描述

使用minipage正值pos\noindent用於第一行。輸出結果與您的預期相符嗎?我使用report文檔類別作為範例並顯示頁面的框架。

\documentclass{report}
\usepackage{showframe}
\usepackage{tkz-euclide}
\begin{document}
\noindent\begin{minipage}[t]{0.475\linewidth}
    \textsf{\textbf{Scalene Triangle}}
    \newline\newline
        \begin{tikzpicture}
            \draw (0,0) -- (1,2) -- (3,1.75) -- (0,0);
        \end{tikzpicture}
\end{minipage}
\begin{minipage}[t]{0.475\linewidth}
    \textsf{\textbf{Isosceles Triangle}}
    \newline\newline
        \begin{tikzpicture}
            \coordinate (A) at (0,0);
            \coordinate (B) at (4,0);
            \coordinate (C) at (2,1.5);
            \draw (0,0) -- (4,0) -- (2,1.5) -- (0,0);
            \tkzMarkSegment[color=black,pos=.5,mark=|](A,C)
            \tkzMarkSegment[color=black,pos=.5,mark=|](B,C)
            \tkzLabelAngle[pos=0.33](B,A,C){$\circ$}
            \tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
        \end{tikzpicture}
\end{minipage}
\newline\newline
\begin{minipage}[t]{0.475\linewidth}
    \textsf{\textbf{Equilateral Triangle}}
    \newline\newline
        \begin{tikzpicture}
            \coordinate (A) at (0,0);
            \coordinate (B) at (3,0);
            \coordinate (C) at (1.5,{1.5*sqrt(3)});
            
            \draw (A) -- (B) -- (C) -- cycle;
            \tkzLabelAngle[pos=0.33](B,A,C){$\circ$}
            \tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
            \tkzLabelAngle[pos=0.33](A,C,B){$\circ$}
        \end{tikzpicture}
\end{minipage}
\begin{minipage}[t]{0.475\linewidth}
\textsf{\textbf{Right Triangle}}
\newline\newline
\begin{tikzpicture}
            
\end{tikzpicture}
\end{minipage}
\end{document}

在此輸入影像描述

答案2

  1. 第一個解決方案。您並非專門使用 tkz-euclide。你跟 TikZ 混在一起就不好了。

您不使用負值,因為pos正如湯姆所說:您正在使邊界框變大。

使用 Clip,您可以控制 bbox(參見 2)

    \begin{tikzpicture}
        \tkzDefPoints{0/0/A,3/0/B}
        \tkzDefTriangle[equilateral](A,B)\tkzGetPoint{C}
        \tkzDrawPolygon(A,B,C)
        \tkzLabelAngle[pos=0.33](B,A,C){$\circ$}
        \tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
        \tkzLabelAngle[pos=0.33](A,C,B){$\circ$}
    \end{tikzpicture}
  1. 您可以使用以下命令控制 bbox\tkzClipPolygon(A,B,C)

    \begin{tikzpicture}
         \coordinate (A) at (0,0);
         \coordinate (B) at (3,0);
         \coordinate (C) at (1.5,{1.5*sqrt(3)});
         \draw (A) -- (B) -- (C) -- cycle;
         \tkzClipPolygon(A,B,C)
         \tkzLabelAngle[pos=-0.33](C,A,B){$\circ$}
         \tkzLabelAngle[pos=0.33](C,B,A){$\circ$}
         \tkzLabelAngle[pos=-0.33](B,C,A){$\circ$}
     \end{tikzpicture}
    

相關內容