数学问答环境:如何避免混乱的方程式?

数学问答环境:如何避免混乱的方程式?

我想以书的形式写出数学问题和答案,供学生阅读。有人能帮我创建问题、解决方案和提示环境,以便我每次都能添加方程式吗?另外我不明白为什么我的方程式很混乱。

我附上了一张关于解决方案的图片

在此处输入图片描述

\documentclass[12pt]{article}

%i have used few packages 

\usepackage[margin= 1cm]{geometry}
\usepackage{amsmath}
\usepackage{tcolorbox}
\usepackage{multicol}
\usepackage{xcolor}


%document begins here     
    
\begin{document}

%section heading 
\section{Questions on Basic integration}

%question with bold and box 
\begin{tcolorbox}
subsection begins here, the word question should be in bold
\subsection*{Question 1} Solve the following integral. $$\int \sec x(\sec x+\tan x) d x $$ 
\end{tcolorbox}

%solution word in bold
\subsubsection*{Solution}
this is a quick tip, to be highlighted
\textcolor{blue}{$$
\begin{array}{l}
\int \sec ^{2} x d x=\tan x \\
\int \sec x \tan x=\sec x
\end{array}
$$}

%the solution   
$$
\begin{aligned}
\int \sec x(&\sec x+\tan x) d x \\
&=\int\left(\sec ^{2} x+\sec x \tan x\right) d x \\
&=\int \sec ^{2} x d x+\int \sec x \tan x d x \\
&=\tan x+\sec x+C
\end{aligned}
$$

%second question
\begin{tcolorbox}

%question 2 begins here 
\subsection*{Question 2} Solve the following integral. $$\int \frac{1}{x+x\log x} dx$$ 
\end{tcolorbox}

%solution in bold
\subsubsection*{Solution}
\textcolor{blue}{$$
\begin{array}{l}
\text { Put } 1+x \log x=t \\
\text { then, } \frac{1}{x}\; d x=d t
\end{array}
 $$}
 % solution begins
\begin{center}$\displaystyle{
\begin{array}{l}
\int \frac{1}{x+x \log x} d x \\
\text { Simce, } \frac{1}{x} d x=d t \text { and }(1+\log x)=t \\
=\int \frac{d t}{t} \\
=\log (t)+C \\
=\int \log (1+\log x)+C
\end{array}
}$ \end{center}
\end{document}

答案1

像这样?请注意,虽然我提供了名为 的宏的代码\tip,但我没有定义单独的问题和答案环境,因为我认为这样做不会解决混乱问题。(实际上,这些环境可能会加剧混乱问题。)我只能建议您更熟悉该amsmath包的多行数学环境。

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage[margin=2.5cm,a4paper]{geometry}
\usepackage{amsmath,tcolorbox} 

\newcommand\tip[1]{\smash{\boxed{\color{blue}\array{r} #1 \endarray}}}
\begin{document}

\section{Questions on basic integration}

\begin{tcolorbox}
\subsection*{Question 1} Solve the following integral.
\quad$\displaystyle \int \sec x(\sec x+\tan x)\, dx $
\end{tcolorbox}

\paragraph{Solution}  
\begin{align*}
&\int \sec x(\sec x+\tan x)\, dx 
   \hspace{3cm} \tip{ \int \sec ^{2} x\, dx=\tan x \\[1ex]
                      \int \sec x \tan x \,dx=\sec x} \\
&\quad=\int\bigl(\sec ^{2} x+\sec x \tan x\bigr)\, dx \\
&\quad=\int \sec ^{2} x\, dx+\int \sec x \tan x\, dx \\
&\quad=\tan x+\sec x+C
\end{align*}



\begin{tcolorbox}
\subsection*{Question 2} Solve the following integral. 
\quad$\displaystyle\int \frac{1}{x+x\log x}\,dx$
\end{tcolorbox}

\paragraph{Solution}
\begin{align*}
&\int \frac{1}{x+x \log x}\, dx \\
&\quad= \int \frac{1}{x(1+\log x)}\, dx 
  \hspace{3cm}\tip{\text{\textbf{Tip:} Put } 1+\log x = t \\[1ex]
                   \text{then } \frac{1}{x}\, dx = dt} \\
&\quad=\int \frac{dt}{t} \\
&\quad=\log (t)+C \\
&\quad=\int \log (1+\log x)+C
\end{align*}

\end{document}

附录回答 OP 的后续问题之一。可以定义一个\question 如下(序言部分):

\newcommand\question[2]{%
   \tcolorbox 
   \subsection*{Question #1} 
   Solve the following integral.\quad$\displaystyle #2$ 
   \endtcolorbox}

然后\question{1}{\int \sec x(\sec x+\tan x)\, dx}在文档正文中写入。

答案2

这就是你想要的吗?

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}
\usepackage{mdframed}
   \mdfsetup{
      leftmargin=-5,
      rightmargin=-5,
      innerleftmargin=5,% Distance from content to frame.  To align the content with
      innerrightmargin=5,% the surrouding text, the sum of leftmargin and innerleftmargin must be zero.
      linecolor=white,% The frame consists of inner-, middle-, and outerline.  linecolor changes all three.
      innertopmargin=0\topskip,
   }
   \mdtheorem[backgroundcolor=PineGreen!15!white]{tip}{Tip}%[section] % Uncomment if you want to include section number.
   \mdtheorem{quest}{Question}%[section] % Uncomment if you want to include section number.
   \mdtheorem{sol}{Solution}%[section] % Uncomment if you want to include section number.
\newcommand{\dd}[0]{\,\mathrm{d}} % puts a thin space and an upright 'd'.

\begin{document}
 
\section{Questions on Basic integration}
   
   \begin{quest}
      Solve the following integral:
      \begin{equation*}
         \int \sec x(\sec x+\tan x) \dd x.
      \end{equation*}
   \end{quest}%
   %
   \begin{sol*}
      \begin{tip*}
         \begin{align*}
            \int \sec^{2} x \dd x    &= \tan x + C\\
            \int \sec x \tan x \dd x &= \sec x + C
         \end{align*}
      \end{tip*}%
      %
      \begin{align*}
         \int \frac{1}{x+x \log x} \dd x  &= \int\frac{1}{x(1+\log(x))} \dd x\\
         &= \int \frac{\dd t}{t} \\
         &= \log (t)+C \\
         &= \log (1+\log x)+C
      \end{align*}
   \end{sol*}
\end{document}

在此处输入图片描述


编辑:正如您在评论中要求的“问题 1”后没有换行符,这里是一个更新版本。

\documentclass[12pt]{article}
\usepackage{amsmath,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{mdframed}
\mdfsetup{
   leftmargin=-5,
   rightmargin=-5,
   innerleftmargin=5,% Distance from content to frame.  To align the content with
   innerrightmargin=5,% the surrouding text, the sum of leftmargin and innerleftmargin must be zero.
   linecolor=white,% The frame consists of inner-, middle-, and outerline.  linecolor changes all three.
   innertopmargin=0\topskip,
}

\newtheorem{quest}{Question}   % for numbered questions
\newtheorem*{quest*}{Question} % for unnumbered questions
\newtheorem{tip}{Tip}          % for numbered tips
\newtheorem*{tip*}{Tip}        % for unnumbered tips
\surroundwithmdframed[backgroundcolor=PineGreen!15!white]{tip}  % get the shiny box around (numbered) tips.
\surroundwithmdframed[backgroundcolor=PineGreen!15!white]{tip*} % get the shiny box around (unnumbered) tips.
\newtheorem{sol}{Solution}     % for numbered solutions
\newtheorem*{sol*}{Solution}   % for unnumbered solutions

\newcommand{\dd}[0]{\,\mathrm{d}} % puts a thin space and an upright 'd'.

\begin{document}
   \section{Questions on Basic integration}
   \begin{quest}
      Solve the following integral:
      \begin{equation*}
         \int \sec x(\sec x+\tan x) \dd x.
      \end{equation*}
   \end{quest}%
   %
   \begin{sol*}
      ~ % For some reason the tip-environment covers the word 'solution' when there is nothing between them.
      \begin{tip*} Here can be some text.
         \begin{align*}
            \int \sec^{2} x \dd x    &= \tan x + C\\
            \int \sec x \tan x \dd x &= \sec x + C
         \end{align*}
      \end{tip*}%
      %
      \begin{align*}
         \int \frac{1}{x+x \log x} \dd x  &= \int\frac{1}{x(1+\log(x))} \dd x\\
         &= \int \frac{\dd t}{t} \\
         &= \log (t)+C \\
         &= \log (1+\log x)+C
      \end{align*}
   \end{sol*}
\end{document}

相关内容