建立一個可以插入 tikzpicture 的新環境

建立一個可以插入 tikzpicture 的新環境

我正在嘗試在序言中創建一個新環境,該環境將在每個圖表中心的上方和下方放置一個空間,

\documentclass{book}

\usepackage{blindtext}
\usepackage{tikz}
\usepackage{tkz-euclide}

\newenvironment{proposition}
{\begin{center}\em}
{\end{center}}

%\newenvironment{diagram}
%\vspace*{\fill}
    %{\begin{center}\em}
    %{\end{center}}
%\vspace*{\fill}

\begin{document}

\begin{proposition}
        On a given finite right line (AB) to construct an equilateral triangle.
 \end{proposition}


%\begin{diagram}
\begin{tikzpicture}
\tkzDefPoint(0,0){A} 
\tkzDefPoint(1.25,0){B} 
\tkzDrawSegment(A,B) 
\tkzLabelPoint[left](A){$A$} 
\tkzLabelPoint[right](B){$B$}
\end{tikzpicture}
%\end{diagram]

\end{document}

我認為我以錯誤的方式處理整個事情,因為沒有環境它渲染得很好,有什麼提示嗎?我在那裡找不到任何例子。我隱藏了導致程式碼混亂的部分。

答案1

嘗試使用此程式碼將其置中tikzpicture並在前後新增空格。

\documentclass{book}

\usepackage{blindtext}
\usepackage{tikz}
\usepackage{tkz-euclide}

\newenvironment{proposition}
{\begin{center}\em}
    {\end{center}}


\newenvironment{diagram}
{\begin{center}\vspace*{10pt}\begin{tikzpicture}}
    {\end{tikzpicture}\vspace*{-5pt}\end{center}}

\begin{document}
    
\begin{proposition}
    On a given finite right line (AB) to construct an equilateral triangle.
\end{proposition}
            
\begin{diagram}
        \tkzDefPoint(0,0){A} 
        \tkzDefPoint(1.25,0){B} 
        \tkzDrawSegment(A,B) 
        \tkzLabelPoint[left](A){$A$} 
        \tkzLabelPoint[right](B){$B$}
\end{diagram}
    
Some text.
    
\end{document}

A

相關內容