LaTeX双栏书籍文档:如何将公式标题置于外侧边距?
解决方案
核心思路:重定义eqfloat的标题输出逻辑,自动绑定外侧边距
无需逐个修改现有公式代码,仅在导言区添加配置即可让公式标题自动移至twoside文档的外侧边距,以下提供两种实用方案:
方案1:基于marginpar的轻量实现
直接修改eqfloat内部的标题生成命令,将标题内容输出到LaTeX原生的外侧边距区域,适配twoside自动识别奇偶页:
\documentclass[twoside]{book} \usepackage{sidecap} \usepackage{eqfloat} \usepackage{amsmath} % 重定义eqfloat标题,转移至外侧边距 \makeatletter \renewcommand{\@eqfloat@caption}[2]{% \marginpar{% 自动适配twoside外侧边距 \raggedright \textbf{#1 \theequation}% 标题前缀+公式编号 \ifx\@empty#2\@empty\else: #2\fi% 标题文本(为空则不显示冒号) }% \ignorespaces } \makeatother % 调整边距参数,适配标题长度 \setlength{\marginparwidth}{3cm} \setlength{\marginparsep}{0.5cm} \begin{document} \chapter{测试章节} \section{公式示例} % 原有eqfloat环境无需修改 \begin{eqfloat}[ht] \begin{equation} E=mc^2 \end{equation} \caption{质能转换方程} \end{eqfloat} \begin{eqfloat}[ht] \begin{equation} \nabla^2 \psi + k^2 \psi = 0 \end{equation} \caption{亥姆霍兹方程} \end{eqfloat} \end{document}
- 优势:零侵入式修改现有公式代码,原生适配twoside布局,无需额外依赖包。
- 调整技巧:若标题过长,可增大
marginparwidth数值,或在marginpar内添加\small缩小字号。
方案2:结合caption包实现统一样式
如果需要让公式标题与sidecap生成的图/表标题风格完全统一,可借助caption包的侧边标题机制:
\documentclass[twoside]{book} \usepackage{sidecap} \usepackage{eqfloat} \usepackage{amsmath} \usepackage{caption} % 全局配置侧边标题样式(同步图/表/公式) \captionsetup{ margin=outside, % 强制标题放在外侧边距 justification=raggedright, singlelinecheck=false, labelsep=colon, font=small } % 让eqfloat调用caption包的标题生成逻辑 \makeatletter \renewcommand{\@eqfloat@caption}[2]{% \caption{#2}% 直接复用caption的侧边样式 } \makeatother % 调整边距参数 \setlength{\marginparwidth}{3cm} \setlength{\marginparsep}{0.5cm} \begin{document} \chapter{测试章节} \section{统一样式示例} \begin{eqfloat}[ht] \begin{equation} \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi} \end{equation} \caption{高斯积分公式} \end{eqfloat} % 同步测试sidecap的图标题 \begin{SCfigure}[][ht] \centering \rule{5cm}{3cm} % 占位图 \caption{测试侧边图标题} \end{SCfigure} \end{document}
- 优势:实现图、表、公式标题样式完全统一,可通过
captionsetup批量调整字体、对齐方式等细节。
常见问题修复
- 标题与公式重叠:增大
marginparsep的数值,拉开正文与边距标题的间距。 - 奇偶页边距偏移:确保文档类指定
twoside,LaTeX会自动处理奇偶页的外侧边距逻辑。 - 标题换行混乱:在
captionsetup中添加format=hang,实现标题文本的悬挂缩进。
内容的提问来源于stack exchange,提问作者Nicholas Tovazzi
相关产品推荐
相关产品推荐

