数学溢出 tcolorbox-如何修复?

数学溢出 tcolorbox-如何修复?

我正在做一些笔记,但我不知道如何阻止数学块从 tcolorbox 中溢出。有什么方法可以解决这个问题吗?:

\documentclass{article}

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{todonotes}
\usepackage{lipsum}
\usepackage{tikz} 
\usepackage[framemethod=tikz]{mdframed}

\parindent 0in % controls indentation of paragraph start
\parskip 1em % controls the spacing between paragraphs
\linespread{1.5} % controls the line spacing

\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{hooks}

\newtcbtheorem[number within=section]{defn}{Definition}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}


% Meta information
\title{Algorithms}

\date{\today}

\begin{document}
    \tcbset{before app=\parfillskip0pt}

    \maketitle
    
    \section{Asymptotic Analysis}
    \begin{defn}{$O(n)$ notation}{}
    % \begin{defn}[]{}
        $O(g(n)) = \left\{f(n): \text{there exist positive constants} \, c, n_0 \, \text{such that}:
        0 \leq c g(n) \right\} \text{for all} \, n \geq n_0$.
    \end{defn}
\end{document}

其结果如下:

在此处输入图片描述

答案1

您可以通过将文本部分切换回文本模式来避免此问题。这允许 latex 在那里添加换行符:

\documentclass{article}

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{todonotes}
\usepackage{lipsum}
\usepackage{tikz} 
\usepackage[framemethod=tikz]{mdframed}

\parindent 0in % controls indentation of paragraph start
\parskip 1em % controls the spacing between paragraphs
\linespread{1.5} % controls the line spacing

\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{hooks}

\newtcbtheorem[number within=section]{defn}{Definition}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}


% Meta information
\title{Algorithms}

\date{\today}

\begin{document}
    \tcbset{before app=\parfillskip0pt}

    \maketitle
    
    \section{Asymptotic Analysis}
    \begin{defn}{$O(n)$ notation}{}
    % \begin{defn}[]{}
        \raggedright
        $O(g(n)) = \left\{f(n):\right.$ there exist positive constants $c, n_0$ such that: $\left.0 \leq c g(n) \right\}$ for all $n \geq n_0$.
    \end{defn}
\end{document}

在此处输入图片描述

相关内容