將參數插入新環境

將參數插入新環境

有人可以幫助我嗎?我有這個:

 %Diagram environment
 \newenvironment{diagram}%
 {\stepcounter{CountDiag}\vspace*{10pt}%

 \begin{center}%
     \begin{tikzpicture}}%
         {\end{tikzpicture}\vspace*{-5pt}\par Diagram~\theCountDiag%
 \end{center}}%

它工作正常,但我想補充一點:

  \tkzSetUpCompass[color=blue]

所以我不必將它放在我使用的每個圖表中。

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

 %Diagram environment
 \newenvironment{diagram}%
 {\stepcounter{CountDiag}\vspace*{10pt}%

 \begin{center}%
 \begin{tikzpicture}}%
    {\end{tikzpicture}\vspace*{-5pt}\par Diagram~\theCountDiag%
 \end{center}}%

 \newcounter{CountDiag}\counterwithin*{CountDiag}{section}%

 \begin{document}

 \begin{diagram}
 \tkzDefPoint(0,0){A}
 \tkzDefPoint(3,0){B}
    \tkzDrawCircle[blue](A,B)

    \tkzDrawPoints(A,B)
    \tkzLabelPoints(A,B)
    
    \tkzDrawSegment[red](A,B)
 \end{diagram}
 \end{document}

答案1

只需在“開始”部分中添加指令即可。

不過,我會做一些重構。

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

\usepackage{lipsum}

%Diagram environment
\newenvironment{diagram}
 {%
  \par\addvspace{10pt}%
  \centering
  \stepcounter{CountDiag}
  \tkzSetUpCompass[color=blue]
  \begin{tikzpicture}
}{%
  \end{tikzpicture}\par\nopagebreak
  \vspace{5pt}
  Diagram~\theCountDiag\par
  \addvspace{10pt}
}
\newcounter{CountDiag}\counterwithin*{CountDiag}{section}%

\begin{document}

\lipsum[1][1-4]

\begin{diagram}
  \tkzDefPoint(0,0){A}
  \tkzDefPoint(3,0){B}
  \tkzDrawCircle[blue](A,B)
  \tkzDrawPoints(A,B)
  \tkzLabelPoints(A,B)
  \tkzDrawSegment[red](A,B)
\end{diagram}

\lipsum[2]

\end{document}

調整間距以滿足您的需求。您\addvspace不會累積可能已經存在的垂直間距。

在此輸入影像描述

相關內容