我正在尝试找到一种方法来创建一个或多个环境,以便我可以创建类似我这里的东西,但自动对各部分进行编号并打印文本,例如步骤 1.....图表 1.....步骤 2.....图表 2......而不必全部输入,并使用图形等。这可能吗,还是我只是在浪费我和你的时间?
\documentclass{book}
\usepackage{blindtext}
\usepackage{tikz}
\usepackage{tkz-euclide}
\newcommand{\AB}{0.7} % A and B added <<<<<<<<<<<<<<
\newcommand{\C}{1.0} % C added <<<<<<<<<<<<<<
\newcommand{\Asize}{0.25} % Angle added <<<<<<<<<<<<<<
\newcommand{\mylipsum}{just dummy text}
\newcommand{\mylipsums}{Step 1}
% Standard packages
\usepackage{
float,
graphicx
}
% Set page margins
\usepackage[top=1.0in, bottom=1.0in, left=1.0in, right=1.0in]{geometry}
\setlength{\marginparwidth}{0pt}
% Set nice page headers
\usepackage{fancyhdr}
\pagestyle{fancy}
% Paragraph style
\setlength{\parindent}{0em}
\setlength{\parskip}{1em}
% Proposition environment
\newenvironment{proposition}
{\begin{center}\em}
{\end{center}}
%Diagram enviroment
\newenvironment{diagram}
{\begin{center}\vspace*{10pt}\begin{tikzpicture}}
{\end{tikzpicture}\vspace*{-5pt}\end{center}}
\setcounter{chapter}{-1}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{}{0pt}{\Huge}
\titlespacing*{\chapter}
{0pt}{0pt}{30pt}
\titleformat{\section}[display]
{\normalfont\huge\bfseries}{}{-20pt}{\Large}
\titlespacing*{\section}
{0pt}{0pt}{10pt}
\begin{document}
\chapter{example}
\section{some text and diagrams}
\begin{proposition}
\mylipsum
\end{proposition}
\begin{diagram}
\tkzDefPoints{-\AB/0/A,\AB/0/B,0/\C/C}
\tkzDrawPolygon[fill=green,opacity=0.5](A,B,C)
\tkzLabelPoints[left](A)
\tkzLabelPoints[right](B)
\tkzLabelPoints[above](C)
\tkzMarkSegment[mark=|](A,C)
\tkzMarkSegment[mark=|](B,C)
\end{diagram}
\mylipsums\\
\mylipsum
\begin{diagram}
\tkzDefPoints{-\AB/0/A,\AB/0/B,0/\C/C}
\tkzDrawPolygon[fill=green,opacity=0.5](A,B,C)
\tkzLabelPoints[left](A)
\tkzLabelPoints[right](B)
\tkzLabelPoints[above](C)
\tkzMarkSegment[mark=||](A,C)
\tkzMarkSegment[mark=||](B,C)
\end{diagram}
\mylipsums\\
\mylipsum
\end{document}
答案1
尝试
\newcounter{CountStep}
\newenvironment{diagram}
{\begin{center}\vspace*{10pt}\begin{tikzpicture}}
{\end{tikzpicture}\vspace*{-5pt}\par\stepcounter{CountStep} Step=~\theCountStep\end{center}}
或者
\newcounter{CountStep}
\newcounter{CountDiag}
\newenvironment{diagram}
{\begin{center}\stepcounter{CountStep}\stepcounter{CountDiag}\vspace*{10pt} Step~\theCountStep\par\begin{tikzpicture}}
{\end{tikzpicture}\vspace*{-5pt}\par Diagram~\theCountDiag
\end{center}}