2

Could anybody help me I don't really know what I am doing with new environments. I have this:

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

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

It works fine but I would like to add:

  \tkzSetUpCompass[color=blue]

So I don't have to put it in every diagram I use.

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

\tkzDrawPoints(A,B)
\tkzLabelPoints(A,B)

\tkzDrawSegment[red](A,B)

\end{diagram} \end{document}

Paul A
  • 1,055
  • 4
  • 14
  • Please, note that I made a few small changes after you posted the full example. – egreg Feb 01 '24 at 22:29
  • 1
    You don't need to place this line in the environment. Simply place it outside and at the beginning of the document, and the style will be valid for all figures. Then if you need a different style in a special figure, use a local style. \tikzset{compass style/.style={...} . You can read : https://tex.stackexchange.com/questions/52372/should-tikzset-or-tikzstyle-be-used-to-define-tikz-styles – Alain Matthes Feb 01 '24 at 22:33

1 Answers1

2

Just add the instruction in the “begin” part.

I'd do some refactoring, though.

\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} \tkzDrawCircleblue \tkzDrawPoints(A,B) \tkzLabelPoints(A,B) \tkzDrawSegmentred \end{diagram}

\lipsum[2]

\end{document}

Adjust the spacings to suit your needs. With \addvspace you don't cumulate vertical spacings that might already be present.

enter image description here

egreg
  • 1,121,712