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

LaTeX/Overleaf子图实现问题:解决Underfull \hbox错误与对齐异常

LaTeX子图排版错误(Underfull \hbox)及对齐问题解决

问题现象

  • 编译时出现Underfull \hbox (badness 10000)错误
  • 子图横向对齐效果不符合预期

问题原因

  1. 包冲突:同时加载subfigure和subcaption两个子图相关包,前者是旧版本包,后者是现代标准子图包,二者混用会干扰排版逻辑
  2. 宽度分配不合理:三个子图各占0.3\textwidth,总宽度仅为0.9\textwidth,剩余空间用\hfill填充时易出现间隙过大、对齐偏移问题
  3. 图片尺寸过小:图片宽度设为0.3\linewidth,导致图片在子图框内占比过低,视觉不协调且可能加剧排版错位

修正方案

  1. 移除冲突包:删除\usepackage{subfigure},仅保留subcaption包
  2. 调整子图宽度:将每个子图宽度设为0.32\textwidth,三个子图总宽度接近\textwidth,配合\hfill可实现均匀对齐
  3. 放大图片占比:将图片宽度设为\linewidth,让图片填满子图可用宽度,优化视觉效果
  4. 规范标签格式:LaTeX标签内不要包含空格,避免后续引用出错

修正后的完整代码

\documentclass[a4paper,oneside,11pt]{report}
\usepackage{subcaption} % 仅保留现代子图包
\usepackage{graphicx} % 显式加载图形包,确保图片正常编译
\begin{document}
\begin{figure}[htbp] % 添加位置参数,提升排版灵活性
     \begin{subfigure}[b]{0.32\textwidth}
         \centering
         \includegraphics[width=\linewidth]{./img/matrices/Logestic_Regression.png} % 图片占满子图宽度
         \caption{Logestic Regression}
         \label{fig:LogisticRegression} % 标签移除空格
     \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.32\textwidth}
         \centering
         \includegraphics[width=\linewidth]{./img/matrices/Naive_Bayes.png}
         \caption{Naive Bayes}
         \label{fig:NaiveBayes}
     \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.32\textwidth}
         \centering
         \includegraphics[width=\linewidth]{./img/matrices/Support_Vector_Machine.png}
         \caption{SVM}
         \label{fig:SVM}
     \end{subfigure}
     \caption{Three simple graphs}
     \label{fig:ThreeGraphs}
\end{figure}
\end{document}

额外说明

  • 若仍出现Underfull \hbox,可在最后一个子图后追加\hfill,或微调子图宽度(比如0.31\textwidth),让总宽度完全适配\textwidth
  • [htbp]参数让LaTeX更灵活地选择图片排版位置,减少不必要的空白区域

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 01:39:40