在逐項列出或枚舉中使用框架

在逐項列出或枚舉中使用框架

我有以下程式碼:

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{classicthesis}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{amsmath,mathtools}
\usepackage{amsfonts}
\usepackage{color}
\usepackage{url}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{tabu}
\usepackage{amsthm}
\usepackage{fourier-orns}
\usepackage{framed}
\usepackage{tcolorbox}
\usepackage[toc,page]{appendix}
\usepackage[all]{xy}

\begin{document}

\begin{enumerate}
\item For the function $y=x,$ find the derivative, $y'.$
\[y'=\lim_{h\to 0}\frac{(x+h)-x}{h}=\lim_{h\to 0}\frac{h}{h}=\lim_{h\to 0}1=1.\]
\item For the function $y=x^2,$ find the derivative, $y'.$
\begin{align*}
y'=\lim_{h\to 0}\frac{(x+h)^2-x^2}{h}&=\lim_{h\to 0}\frac{x^2+2xh+h^2-x^2}{h}\\
&=\lim_{h\to 0}\frac{2xh+h^2}{h}=\lim_{h\to 0}(2x+h)=2x.
\end{align*}
    \begin{center}
        \begin{framed}
For the next two examples, we will use the angle sum formula for sine, which is
\[\sin(\alpha+\beta)=\sin\alpha\cos\beta+\cos\alpha\sin\beta.\]
        \end{framed}
    \end{center}
\item For the function $y=\sin x,$ find the derivative, $y'.$
\begin{align*}
y'=\lim_{h\to 0}\frac{\sin (x+h)-\sin x}{h}&=\lim_{h\to 0}\frac{\sin x\cos h+\cos x\sin h-\sin x}{h}\\
&=\lim_{h\to 0}\frac{\sin x(\cos h-1)+\cos x\sin h}{h}\\
&=\left[\lim_{h\to 0}(\sin x)\left(\frac{\cos h-1}{h}\right)\right]\left[\lim_{h\to 0}(\cos x)\left(\frac{\sin h}{h}\right)\right]\\
&=(\sin x)\cdot 0+(\cos x)\cdot 1\\
&=\cos x,
\end{align*}
where we have used $\displaystyle\lim_{h\to 0}\frac{\sin h}{h}=1$ and $\displaystyle\lim_{h\to 0}\frac{\cos h-1}{h}=0$ from section (1.3).
\item Find $\dfrac{d}{dx}\tan x.$
\begin{align*}
\dfrac{d}{dx}\tan x=\displaystyle\lim_{h\to 0}\dfrac{\tan(x+h)-\tan x}{h}&=\displaystyle\lim_{h\to 0}\left(\dfrac{\sin(x+h)}{h\cos(x+h)}-\dfrac{\sin x}{h\cos x}\right)\\
&=\displaystyle\lim_{h\to 0}\left(\dfrac{\sin(x+h)\cos x-\cos(x+h)\sin x}{h\cos(x+h)\cos x}\right)\\
&=\displaystyle\lim_{h\to 0}\left(\dfrac{\sin[(x+h)-x]}{h\cos(x+h)\cos x}\right)\\
&=\displaystyle\lim_{h\to 0}\left[\left(\dfrac{\sin h}{h}\right)\left(\dfrac{1}{\cos(x+h)\cos x}\right)\right]\\
&=\dfrac{1}{\cos^2(x)}=\sec^2 x.
\end{align*}
\end{enumerate}

\end{document}

我不斷收到錯誤“出了點問題——可能缺少 \item

如何解決這個問題?

答案1

你需要\leavevmode先於framed環境;但是,我想建議您使用該tcolorbox套件(您已經加載)的另一種方法。以下是與原始範例framedtcolorbox具有定義寬度的 a 的比較範例(a\makebox用於使框相對於 居中\textwidth):

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{classicthesis}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{amsmath,mathtools}
\usepackage{amsfonts}
\usepackage{color}
\usepackage{url}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{tabu}
\usepackage{amsthm}
\usepackage{fourier-orns}
\usepackage{framed}
\usepackage[many]{tcolorbox}
\usepackage[toc,page]{appendix}
\usepackage[all]{xy}
\usepackage[margin=2cm,showframe]{geometry}

\begin{document}

\begin{enumerate}
\item For the function $y=x,$ find the derivative, $y'.$
\[y'=\lim_{h\to 0}\frac{(x+h)-x}{h}=\lim_{h\to 0}\frac{h}{h}=\lim_{h\to 0}1=1.\]
\item For the function $y=x^2,$ find the derivative, $y'.$
\begin{align*}
y'=\lim_{h\to 0}\frac{(x+h)^2-x^2}{h}&=\lim_{h\to 0}\frac{x^2+2xh+h^2-x^2}{h}\\
&=\lim_{h\to 0}\frac{2xh+h^2}{h}=\lim_{h\to 0}(2x+h)=2x.
\end{align*}
      \begin{center}\leavevmode
        \begin{framed}
For the next two examples, we will use the angle sum formula for sine, which is
\[\sin(\alpha+\beta)=\sin\alpha\cos\beta+\cos\alpha\sin\beta.\]
        \end{framed}
        \end{center}
        \makebox[\linewidth]{%
          \begin{tcolorbox}[arc=0pt,outer arc=0pt,colback=white,width=.6\textwidth]
      For the next two examples, we will use the angle sum formula for sine, which is
      \[\sin(\alpha+\beta)=\sin\alpha\cos\beta+\cos\alpha\sin\beta.\]
        \end{tcolorbox}}
\item For the function $y=\sin x,$ find the derivative, $y'.$
\begin{align*}
y'=\lim_{h\to 0}\frac{\sin (x+h)-\sin x}{h}&=\lim_{h\to 0}\frac{\sin x\cos h+\cos x\sin h-\sin x}{h}\\
&=\lim_{h\to 0}\frac{\sin x(\cos h-1)+\cos x\sin h}{h}\\
&=\left[\lim_{h\to 0}(\sin x)\left(\frac{\cos h-1}{h}\right)\right]\left[\lim_{h\to 0}(\cos x)\left(\frac{\sin h}{h}\right)\right]\\
&=(\sin x)\cdot 0+(\cos x)\cdot 1\\
&=\cos x,
\end{align*}
where we have used $\displaystyle\lim_{h\to 0}\frac{\sin h}{h}=1$ and $\displaystyle\lim_{h\to 0}\frac{\cos h-1}{h}=0$ from section (1.3).
\item Find $\dfrac{d}{dx}\tan x.$
\begin{align*}
\dfrac{d}{dx}\tan x=\displaystyle\lim_{h\to 0}\dfrac{\tan(x+h)-\tan x}{h}&=\displaystyle\lim_{h\to 0}\left(\dfrac{\sin(x+h)}{h\cos(x+h)}-\dfrac{\sin x}{h\cos x}\right)\\
&=\displaystyle\lim_{h\to 0}\left(\dfrac{\sin(x+h)\cos x-\cos(x+h)\sin x}{h\cos(x+h)\cos x}\right)\\
&=\displaystyle\lim_{h\to 0}\left(\dfrac{\sin[(x+h)-x]}{h\cos(x+h)\cos x}\right)\\
&=\displaystyle\lim_{h\to 0}\left[\left(\dfrac{\sin h}{h}\right)\left(\dfrac{1}{\cos(x+h)\cos x}\right)\right]\\
&=\dfrac{1}{\cos^2(x)}=\sec^2 x.
\end{align*}
\end{enumerate}

\end{document}

結果:

在此輸入影像描述

我用了

\usepackage[margin=2cm,showframe]{geometry}

在範例中只是提供了頁面佈局的視覺指南。

答案2

另一個選擇是使用minipage程式碼中所示的環境

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{classicthesis}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{amsmath,mathtools}
\usepackage{amsfonts}
\usepackage{color}
\usepackage{url}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{tabu}
\usepackage{amsthm}
\usepackage{fourier-orns}
\usepackage{framed}
\usepackage{tcolorbox}
\usepackage[toc,page]{appendix}
\usepackage[all]{xy}

\begin{document}

\begin{enumerate}
\item For the function $y=x,$ find the derivative, $y'.$
\[y'=\lim_{h\to 0}\frac{(x+h)-x}{h}=\lim_{h\to 0}\frac{h}{h}=\lim_{h\to 0}1=1.\]
\item For the function $y=x^2,$ find the derivative, $y'.$
\begin{align*}
y'=\lim_{h\to 0}\frac{(x+h)^2-x^2}{h}&=\lim_{h\to 0}\frac{x^2+2xh+h^2-x^2}{h}\\
&=\lim_{h\to 0}\frac{2xh+h^2}{h}=\lim_{h\to 0}(2x+h)=2x.
\end{align*}

\begin{minipage}[c]{0.75\textwidth}
\begin{framed}
For the next two examples, we will use the angle sum formula for sine, which is
\[\sin(\alpha+\beta)=\sin\alpha \cos\beta+\cos\alpha \sin\beta.\]
\end{framed}
\end{minipage}


\item For the function $y=\sin x,$ find the derivative, $y'.$
\begin{align*}
y'=\lim_{h\to 0}\frac{\sin (x+h)-\sin x}{h}&=\lim_{h\to 0}\frac{\sin x\cos h+\cos x\sin h-\sin x}{h}\\
&=\lim_{h\to 0}\frac{\sin x(\cos h-1)+\cos x\sin h}{h}\\
&=\left[\lim_{h\to 0}(\sin x)\left(\frac{\cos h-1}{h}\right)\right]\left[\lim_{h\to 0}(\cos x)\left(\frac{\sin h}{h}\right)\right]\\
&=(\sin x)\cdot 0+(\cos x)\cdot 1\\
&=\cos x,
\end{align*}
where we have used $\displaystyle\lim_{h\to 0}\frac{\sin h}{h}=1$ and $\displaystyle\lim_{h\to 0}\frac{\cos h-1}{h}=0$ from section (1.3).
\item Find $\dfrac{d}{dx}\tan x.$
\begin{align*}
\dfrac{d}{dx}\tan x=\displaystyle\lim_{h\to 0}\dfrac{\tan(x+h)-\tan x}{h}&=\displaystyle\lim_{h\to 0}\left(\dfrac{\sin(x+h)}{h\cos(x+h)}-\dfrac{\sin x}{h\cos x}\right)\\
&=\displaystyle\lim_{h\to 0}\left(\dfrac{\sin(x+h)\cos x-\cos(x+h)\sin x}{h\cos(x+h)\cos x}\right)\\
&=\displaystyle\lim_{h\to 0}\left(\dfrac{\sin[(x+h)-x]}{h\cos(x+h)\cos x}\right)\\
&=\displaystyle\lim_{h\to 0}\left[\left(\dfrac{\sin h}{h}\right)\left(\dfrac{1}{\cos(x+h)\cos x}\right)\right]\\
&=\dfrac{1}{\cos^2(x)}=\sec^2 x.
\end{align*}
\end{enumerate}

\end{document}

相關內容