Skip to content

【Bug】tpfigure / tptable 环境继承正文首行缩进,导致图表整体向右偏移 #3

Description

@K-gihu

问题描述

在正文内容区块(如 xtyjyjfayjjc 等基于 mybox2 的环境)中,使用模板提供的自定义图表环境 tpfiguretptable 插入图片/表格时,图表整体会出现 2em 的首行缩进,视觉上表现为图表向右偏移约 2 个汉字宽度,不符合常规图表居中、与内容区左边界对齐的排版预期。

复现方式

最小复现代码示例:

\documentclass[da]{xdupgtp}

\newcommand\studentNo{XXXX}
\newcommand\thesisTitleOne{XXXX}
\newcommand\thesisTitleTwo{开题报告表XeLaTeX模板}
\newcommand\authorName{XXXX}
\newcommand\major{XXXX}
\newcommand\submajor{XXXX}
\newcommand\advisorName{XXXX}
\newcommand\school{XXXX}
\newcommand\submitDate{2026年7月31日}
\newcommand\subjectSource{国家自然科学基金}

\begin{document}
\section{选题依据}
\begin{xtyj}
\subsection{国内外研究现状}

% 插入测试图,可观察到整体右偏
\begin{tpfigure}
\includegraphics[width=0.8\textwidth]{example-image-a}
\captionof{figure}{测试示意图}
\end{tpfigure}

正文段落验证:本段首行缩进为正常的 2em,用于对比图表偏移量。

\end{xtyj}
\end{document}

编译后可观察到:图表整体左边界与正文首行对齐,而非与正文段落左边界对齐,偏移量与 \parindent 一致。

根本原因

结合类文件源码分析,问题由两点共同导致:

  1. 所有正文区块均基于 mybox2 环境构建,该环境通过 before upper 钩子全局设置了 \setlength{\parindent}{2em},为正文段落开启首行缩进,这是正文排版的正确设置。
  2. 自定义图表环境 tpfiguretptable 内部以 minipage 包裹内容,但环境起始处未添加 \noindent 命令。当图表位于段落开头时,整个 minipage 盒子会被 LaTeX 视为段落首行元素,继承外层的 2em 缩进,最终表现为图表整体右移。

修复建议

tpfiguretptable 两个环境的 minipage 之前添加 \noindent,即可抵消外层的首行缩进,本地验证可完全修复该问题。修改后核心代码如下:

\NewEnviron{tpfigure}{
  \noindent
  \begin{minipage}{\textwidth}
  \vspace*{6bp}
  \centering
  \BODY
  \end{minipage}
}

\NewEnviron{tptable}{
  \noindent
  \begin{minipage}{\textwidth}
  \centering
  \zihao{5}
  \BODY
  \vspace*{6bp}
  \end{minipage}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions