![环境定义问题](https://linux22.com/image/290903/%E7%8E%AF%E5%A2%83%E5%AE%9A%E4%B9%89%E9%97%AE%E9%A2%98.png)
我知道这是一个简单而且非常具体的要求,但我已经研究了一整天了,我真的不明白到底出了什么问题!
\documentclass[12pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsthm,mathtools}
\usepackage{amsmath, textcomp}
\usepackage{titling}
\theoremstyle{definition}
\newtheorem{Gcal}{Grande Caloria \textit{Cal} o \textit{kcal}}[section]
\theoremstyle{definition}
\newtheorem{Pcal}[Gcal]{Piccola Caloria \textit{cal}}
\theoremstyle{definition}
\newtheorem{CalS}[Pcal]{Calore Specifico}
\begin{document}
\chapter{1}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\chapter{2}
\section{2.1}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\begin{itemize}
\itemsep0em
\item[] \begin{Gcal}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{Gcal}
\item[] \begin{Pcal}
blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{Pcal}
\end{itemize}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\begin{CalS}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{CalS}
\end{document}
错误报告
!LaTeX 错误:未定义计数器“Pcal”。请参阅 LaTeX 手册或 LaTeX Companion 了解解释。输入 H 可立即获得帮助。... l.22 \newtheorem{CalS}[Pcal]{Calore Specifico} 您的命令已被忽略。
! LaTeX 错误:环境 CalS 未定义。有关解释,请参阅 LaTeX 手册或 LaTeX Companion。键入 H 获取立即帮助。... l.45 \begin{CalS} 您的命令已被忽略。键入 I 以将其替换为其他命令,或继续执行而不执行该命令。! LaTeX 错误:\begin{document} 以 \end{CalS} 结束。有关解释,请参阅 LaTeX 手册或 LaTeX Companion。键入 H 获取立即帮助。... l.47 \end{CalS} 您的命令已被忽略。
!LaTeX 错误:\begin{document} 结束于 \end{CalS}。请参阅 LaTeX 手册或 LaTeX Companion 了解解释。输入 H 可立即获得帮助。... l.47 \end{CalS} 您的命令已被忽略。
有人能解释一下我做错了什么吗?为什么即使我复制/粘贴了所有内容,只有第三个环境会出现问题?
答案1
当你说
\newtheorem{abc}{Abc}[section]
\newtheorem{xyz}[abc]{Xyz}
你告诉 LaTeX 语句环境abc
必须xyz
共享计数器;所以没有xyz
定义计数器。
你可以做
\theoremstyle{definition}
\newtheorem{Gcal}{Grande Caloria \textit{Cal} o \textit{kcal}}[section]
\newtheorem{Pcal}[Gcal]{Piccola Caloria \textit{cal}}
\newtheorem{CalS}[Gcal]{Calore Specifico}
请注意,一次\theoremstyle{definition}
声明就足够了。
事实上有更好的方法。
\documentclass[12pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsthm,mathtools}
\usepackage{amsmath, textcomp}
\usepackage{titling}
\theoremstyle{definition}
\newtheorem{vardef*}{\vardefname}[section]
\newcommand\vardefname{} % initialize
\newenvironment{vardef}[1]
{\renewcommand\vardefname{#1}\begin{vardef*}}
{\end{vardef*}}
\begin{document}
\chapter{1}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\chapter{2}
\section{2.1}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\begin{vardef}{Grande Caloria \textit{Cal} o \textit{kcal}}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{vardef}
\begin{vardef}{Piccola Caloria \textit{cal}}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{vardef}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\begin{vardef}{Calore Specifico}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{vardef}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{document}
您只有一个用于定义的通用环境,并在声明时给出标题,而不是在序言中为每个定义提供不同的环境。