如何在其他环境中使用方程式章节编号

如何在其他环境中使用方程式章节编号

我创建了一个类似于第一部分的新环境,以便能够在其中输入方程式。

\newenvironment{question}{\begin{enumerate}\bfseries}
                        {\end{enumerate}}

\newenvironment{answer}{\par\vspace{0.2cm}\normalfont}
                        {\vspace{0.2cm}}

我想要做的是把方程式放在回答环境,以及那些在问题他们处于这样的状态:

在此处输入图片描述

这是该示例的完整代码:

\documentclass[12pt, letterpaper]{article}

% ------------------------------------
% Preamble
% ------------------------------------
\usepackage{amsmath}

\newenvironment{question}{\begin{enumerate}\bfseries}
                        {\end{enumerate}}

\newenvironment{answer}{\par\vspace{0.2cm}\normalfont}
                        {\vspace{0.2cm}}

\DeclareMathSizes{12}{14}{10}{8}

% ------------------------------------

\begin{document}

    \begin{question}
        \item Identify if the given vector 
        fields can be electric fields

        \begin{itemize}
            \item \(\vec{A} = A(r)\hat{r}\)
            \item \(\vec{B} = \frac{k}{r^2}\hat{\varphi}\)
            \item \(\vec{C} = c(x^2 \hat{i} + y^2\hat{j} + z^2\hat{k})\)
        \end{itemize}

        If true, determine the charge density 
        that produces them

        \begin{answer}
            We're going to beging with the equation

            \begin{equation}\tag{1.1}
                \vec{A} = A(r)\hat{r}
            \end{equation}

            We know that 

            \begin{equation}\tag{1.2}
                \nabla \times \vec{E}\vec{(r)}=0
            \end{equation}
        \end{answer}        

        \item Calculate the electric field in a
        distance \textit{z} from the center of a
        square loop of side \textit{a} charged 
        with a uniform chatge density \(\lambda_0\)

        \begin{answer}
            In cylindrical coordinates, the charge density of this system is:

            \small
            \begin{equation}\tag{2.1}
                \rho \left( \vec{r}^{\prime} \right) = 
                \frac{\lambda}{\rho_{c}^{\prime}} \delta\left(\rho_{c}^{\prime}-a/2\right) \delta\left(\phi^{\prime}-\phi_{0}\right) \Theta\left(a/2-z\right) \Theta\left(-a/2+z\right)
            \end{equation}
            \normalfont

            Calculating the electric potential:

            \begin{equation}\tag{2.2}
                \varphi(\vec{r}) = 
                \frac{1}{4 \pi \varepsilon_{0}} \int d^{3} r^{\prime} \frac{\rho\left(\vec{r}^{\prime}\right)}{\left\|\vec{r}-\vec{r}^{\prime}\right\|}
            \end{equation}
        \end{answer}

    \end{question}
    
\end{document}

我怎样才能做到这一点而不必把\标签在每个方程中手动输入吗?

答案1

欢迎来到 TeX.SE...您可以使用标签来实现这一点\numberwithin{equation}{enumi}

\documentclass[12pt, letterpaper]{article}

% ------------------------------------
% Preamble
% ------------------------------------
\usepackage{amsmath}

\newenvironment{question}{\begin{enumerate}\bfseries}
                        {\end{enumerate}}

\newenvironment{answer}{\par\vspace{0.2cm}\normalfont}
                        {\vspace{0.2cm}}

\DeclareMathSizes{12}{14}{10}{8}

% ------------------------------------

\begin{document}

    \begin{question}
        \item Identify if the given vector 
        fields can be electric fields

        \begin{itemize}
            \item \(\vec{A} = A(r)\hat{r}\)
            \item \(\vec{B} = \frac{k}{r^2}\hat{\varphi}\)
            \item \(\vec{C} = c(x^2 \hat{i} + y^2\hat{j} + z^2\hat{k})\)
        \end{itemize}

        If true, determine the charge density 
        that produces them
\numberwithin{equation}{enumi}
        \begin{answer}
            We're going to beging with the equation
            \begin{equation}
                \vec{A} = A(r)\hat{r}
            \end{equation}

            We know that 
            \begin{equation}
                \nabla \times \vec{E}\vec{(r)}=0
            \end{equation}
        \end{answer}        

        \item Calculate the electric field in a
        distance \textit{z} from the center of a
        square loop of side \textit{a} charged 
        with a uniform chatge density \(\lambda_0\)

        \begin{answer}
            In cylindrical coordinates, the charge density of this system is:
            \begin{equation}
                \rho \left( \vec{r}^{\prime} \right) = 
                \frac{\lambda}{\rho_{c}^{\prime}} \delta\left(\rho_{c}^{\prime}-a/2\right) \delta\left(\phi^{\prime}-\phi_{0}\right) \Theta\left(a/2-z\right) \Theta\left(-a/2+z\right)
            \end{equation}
            \normalfont

            Calculating the electric potential:
            \begin{equation}
                \varphi(\vec{r}) = 
                \frac{1}{4 \pi \varepsilon_{0}} \int d^{3} r^{\prime} \frac{\rho\left(\vec{r}^{\prime}\right)}{\left\|\vec{r}-\vec{r}^{\prime}\right\|}
            \end{equation}
        \end{answer}

    \end{question}
    
\end{document}

相关内容