TransWikia.com

How to use the section numbering for equations in other environments

TeX - LaTeX Asked by Yoltic Cruz Tello on December 9, 2020

I’ve created a new environment resembling the section one, to be able to put equations in it.

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

newenvironment{answer}{parvspace{0.2cm}normalfont}
                        {vspace{0.2cm}}

What I want to do is put equations in the answer environment, and those equations to be numbered in the question that they are in, like this:

enter image description here

This is the full code for this example:

documentclass[12pt, letterpaper]{article}

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

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

newenvironment{answer}{parvspace{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^2hat{j} + z^2hat{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}} deltaleft(rho_{c}^{prime}-a/2right) deltaleft(phi^{prime}-phi_{0}right) Thetaleft(a/2-zright) Thetaleft(-a/2+zright)
            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{rholeft(vec{r}^{prime}right)}{left|vec{r}-vec{r}^{prime}right|}
            end{equation}
        end{answer}

    end{question}
    
end{document}

How can I do this without having to put the tag manually in every equation?

One Answer

Welcome to TeX.SE... You can achieve this by using the tag numberwithin{equation}{enumi}

documentclass[12pt, letterpaper]{article}

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

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

newenvironment{answer}{parvspace{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^2hat{j} + z^2hat{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}} deltaleft(rho_{c}^{prime}-a/2right) deltaleft(phi^{prime}-phi_{0}right) Thetaleft(a/2-zright) Thetaleft(-a/2+zright)
            end{equation}
            normalfont

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

    end{question}
    
end{document}

Correct answer by MadyYuvi on December 9, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP