You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LaTeX子图标题与页面居中而非子图居中的问题求助

问题解决:子图并排与标题对齐修正

你的核心问题是**subfigure环境的语法使用错误**,导致子图无法并排,标题对齐也失效。以下是具体修正方案:

一、修正原subfigure包的代码

你的代码错误地将\includegraphics直接作为subfigure环境的参数,正确写法是先指定子图宽度,再在环境内部插入图片。同时调整标题设置,让标题与子图宽度匹配:

\documentclass{article}

\usepackage{graphicx} 
\usepackage{float}
\usepackage{subfigure}
\usepackage{caption}
\renewcommand{\captionfont}{\small\itshape}    
\renewcommand{\figurename}{\textbf{Abb.}} 
\renewcommand{\tablename}{\textbf{Tab.}}

\title{StackOverflowExpl}
\author{me}
\date{September 2023}

\begin{document}

\section{FigureTest}
\begin{figure}[H]
    % 正确语法:subfigure参数仅指定宽度,内部放置图片和标题
    \begin{subfigure}{0.33\textwidth}
        \includegraphics[width=\linewidth]{img/Filter_Vorlage.JPG}
        \captionsetup{width=\linewidth, justification=centering}
        \caption{Ausgangsbild vor Maximum}
    \end{subfigure}
    \hfill % 子图间添加水平间距,确保并排
    \begin{subfigure}{0.33\textwidth}
        \includegraphics[width=\linewidth]{img/Filter_Max5x5.JPG}
        \captionsetup{width=\linewidth, justification=centering}
        \caption{5x5 Maximum Filter angewendet}
    \end{subfigure}
\end{figure} 

\end{document}

修改说明:

  • 将\includegraphics从subfigure的参数移到环境内部,subfigure仅负责定义子图容器宽度
  • 图片宽度设为\linewidth,保证图片完全适配子图容器
  • captionsetup用width=\linewidth让标题宽度与子图一致,justification=centering实现标题在子图范围内居中
  • 子图间的\hfill会自动填充空白,确保两张子图在一行内均匀分布

二、推荐使用更现代的subcaption包

旧版subfigure包已停止维护,推荐换成subcaption包,语法更清晰,兼容性更强:

\documentclass{article}

\usepackage{graphicx} 
\usepackage{float}
\usepackage{subcaption} % 替换subfigure为subcaption
\usepackage{caption}
\renewcommand{\captionfont}{\small\itshape}    
\renewcommand{\figurename}{\textbf{Abb.}} 
\renewcommand{\tablename}{\textbf{Tab.}}

\title{StackOverflowExpl}
\author{me}
\date{September 2023}

\begin{document}

\section{FigureTest}
\begin{figure}[H]
    \begin{subfigure}{0.33\textwidth}
        \includegraphics[width=\linewidth]{img/Filter_Vorlage.JPG}
        \captionsetup{width=\linewidth, justification=centering}
        \caption{Ausgangsbild vor Maximum}
    \end{subfigure}
    \hfill
    \begin{subfigure}{0.33\textwidth}
        \includegraphics[width=\linewidth]{img/Filter_Max5x5.JPG}
        \captionsetup{width=\linewidth, justification=centering}
        \caption{5x5 Maximum Filter angewendet}
    \end{subfigure}
\end{figure} 

\end{document}

为什么选subcaption?

  • 支持更多自定义选项,比如子图标题格式、间距调整
  • 与caption包兼容性更好,不会出现冲突
  • 是当前LaTeX社区的主流选择,官方文档更完善

内容的提问来源于stack exchange,提问作者Erdnuss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 03:23:36