目录中的内联数学

目录中的内联数学

我在所有文档中都使用 displaystyle 来显示数学表达式,但我只想在目录中使用内联样式。这可能吗?

\documentclass{article}
\usepackage{amsmath}
\everymath{\displaystyle}
\begin{document}
\tableofcontents
\section{This is an integral $\int_{0}^{1}f(t){\rm d}t$}
\section{This is a series $\sum\limits_{n\ge1}^{+\infty}\frac{1}{n^{2}}$}
\end{document}

答案1

您可以使用开关:

\documentclass{article}
\usepackage{amsmath}
\newif\ifinToC
\addtocontents{toc}{\protect\inToCtrue}
\everymath{\ifinToC\else\displaystyle\fi}
\begin{document}
\tableofcontents
\section{This is an integral $\int_{0}^{1}f(t){\rm d}t$}
\section{This is a series $\sum\limits_{n\ge1}^{+\infty}\frac{1}{n^{2}}$}
\end{document}

但也许最好将\displaystyle数学限制在标题内,因为在文本内,它很丑陋:

\documentclass{article}
\usepackage{amsmath}
\newif\ifinToC
\DeclareRobustCommand*{\CDS}{\ifinToC\else\displaystyle\fi}
\addtocontents{toc}{\protect\inToCtrue}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\section{This is an integral $\CDS \int_{0}^{1}f(t){\rm d}t$}
Wouldn't it be besser to not have the display style here inside paragraphs
like this, and to use $\int_{0}^{1}f(t){\rm d}t$ here. \blindtext
Because using $\CDS \int_{0}^{1}f(t){\rm d}t$ make the paragraph very
ugly, at least if you have several such formulars inside one paragraph, like
here: $\CDS\sum\limits_{n\ge1}^{+\infty}\frac{1}{n^{2}}$ \blindtext

\section{This is a series $\CDS\sum\limits_{n\ge1}^{+\infty}\frac{1}{n^{2}}$}
\end{document}

答案2

如果您必须使用\everymath{\displaystyle},我建议您使用可选参数 来\section指示 LaTeX 在目录中以数学模式排​​版数学材料。此方法还允许您进行进一步的更改,这将有利于文档的外观,例如对目录条目和节标题本身\textstyle使用内联分数符号。\boldmath

我认为您已经\textstyle在其他地方使用指令来覆盖的效果\everymath{\displaystyle},对吗?

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath}
\everymath{\displaystyle}
\begin{document}

\tableofcontents

\bigskip\hrule\bigskip % optional: insert a visual separator

\section[The integral $\textstyle\int_0^1 f(t)\,\mathrm{d}t$]%
   {\boldmath The integral $\int_0^1 \!f(t)\,\mathrm{d}t$}
\dots

\section[The sum $\textstyle\sum_{n=1}^{\infty}n^{-2}$]%
   {\boldmath The sum $\sum_{n=1}^{\infty}\frac{1}{n^2}$}
\dots

\end{document}

相关内容