6

When compiling the MWE below with pdflatex, I get the warnings Underfull \hbox (badness 10000) in paragraph at lines 26--27 and Underfull \hbox (badness 10000) in paragraph at lines 36--37.

I tried to avoid this by using \hfill between the subfigures, but it didn't work.

\documentclass{scrbook}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{subcaption}
\usepackage{gnuplottex}
\usepackage{xparse}
\ExplSyntaxOn
\DeclareExpandableDocumentCommand{\convertlen}{ O{cm} m }
 {
  \dim_to_unit:nn { #2 } { 1 #1 } cm
 }
\ExplSyntaxOff

\begin{document}
\begin{figure}[htbp]
 \centering
 \begin{subfigure}[b]{.45\textwidth}
  \begin{gnuplot}[terminal = cairolatex, terminaloptions = {size \convertlen{\textwidth},\convertlen{.3\textheight}}]
   plot sin(x)
  \end{gnuplot}
  \caption{A subfigure}
  \label{fig:1a}
 \end{subfigure}%
 \hfill
 \begin{subfigure}[b]{.45\textwidth}
  \begin{gnuplot}[terminal = cairolatex, terminaloptions = {size \convertlen{\textwidth},\convertlen{.3\textheight}}]
   plot sin(x)
  \end{gnuplot}
  \caption{Another subfigure}
  \label{fig:1b}
 \end{subfigure}
 \caption{A figure}\label{fig:1}
\end{figure}
\end{document}
Blub Bla
  • 317
  • Your code gives me the error ! Undefined control sequence. \convertlen code #1#2->\dim_to_unit:nn – Gonzalo Medina Aug 13 '15 at 15:24
  • @GonzaloMedina I need the \convertlen command to specify the width of the gnuplot graph. I found the code for \convertlen here and don't fully understand it. But it does what I want, except the underfull boxes. – Blub Bla Aug 13 '15 at 16:04
  • 1
    I don't know why, but changing both occurrences of \convertlen{\textwidth} to \convertlen{.99\textwidth} makes the warnings go away. – Gonzalo Medina Aug 13 '15 at 17:40
  • @GonzaloMedina Thanks, inserting .99 worked. Who would have thought that you need a smaller figure to get rid of the underfull box warning. – Blub Bla Aug 13 '15 at 19:52

1 Answers1

7

If you add

\showboxdepth3
\showboxbreadth10
\tracingonline1

to see which box is underfull you see

\hbox(178.66272+0.0)x188.21371
.\hbox(0.0+0.0)x0.0
.\hbox(178.66272+0.0)x187.69623
..\special{ps: currentpoint currentpoint translate 1 1 scale neg exch neg exch 
t\ETC.}
..\hbox(178.66272+0.0)x0.0, glue set - 187.69623fil
...\hbox(178.66272+0.0)x187.69623 []
...\glue 0.0 plus 1.0fil minus 1.0fil
..\special{ps: currentpoint currentpoint translate 1 1 div 1 1 div scale neg ex
c\ETC.}
.\glue(\rightskip) 0.0

So the line is trying to be 188.21371pt but the box with the plot is 187.69623pt the only glue on the line is \rightskip and that is zero, so the box is underful.

That's slightly odd as a one line paragraph usually has \parfillskip at the end but that has been removed here somewhere in the verbatim handling for gnuplot.

rather than debug exactly where \parfillskip went, a simpler fix is to make \rightskip non zero, and if you uncomment the %\centering the warning goes away.

(I updated the name of \dim_to_decimal_in_unit:nn)

\documentclass{scrbook}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{subcaption}
\usepackage{gnuplottex}
\usepackage{xparse}
\ExplSyntaxOn
\DeclareExpandableDocumentCommand{\convertlen}{ O{cm} m }
 {
  \dim_to_decimal_in_unit:nn { #2 } { 1 #1 } cm
 }
\ExplSyntaxOff
%\showoutput
\showboxdepth3
\showboxbreadth10
\tracingonline1
\begin{document}
\begin{figure}[htbp]
 \centering
 \begin{subfigure}[b]{.45\textwidth}
%\centering
\begin{gnuplot}[terminal = cairolatex, terminaloptions = {size \convertlen{\textwidth},\convertlen{.3\textheight}}]
   plot sin(x)
  \end{gnuplot}
  \caption{A subfigure}
  \label{fig:1a}
 \end{subfigure}%
 \hfill
 \begin{subfigure}[b]{.45\textwidth}
\centering
  \begin{gnuplot}[terminal = cairolatex, terminaloptions = {size \convertlen{\textwidth},\convertlen{.3\textheight}}]
   plot sin(x)
  \end{gnuplot}
  \caption{Another subfigure}
  \label{fig:1b}
 \end{subfigure}
 \caption{A figure}\label{fig:1}
\end{figure}
\end{document}
David Carlisle
  • 757,742