1

I am trying to compile the following code:

\documentclass{article}
\usepackage{graphicx,algpseudocode,algorithm,multirow,hyperref,subfig,cancel,natbib,epstopdf,xspace}

\begin{document}

\clubpenalty=10000
\widowpenalty = 10000

\begin{table}
%\newcommand{\tabcolwidth}[1]{\parbox[c]{3cm}{\centering #1}}
\renewcommand\multirowsetup{\centering}
\caption{caption}

\subfloat
{
\resizebox{1.0\linewidth}{!}
{
\begin{tabular}{lrrrr}
\hline
\multirow{2}{*}{A} & \multicolumn{4}{c}{B} \\
  & $20 \%$ & $40 \%$ & $60 \%$ & $80 \%$ \\
\hline
Alg1 & $48.21$ & $48.64$ & $51.13$ & $52.46$ \\
Alg2 & $42.72$ & $46.31$ & $48.56$  & $51.64$ \\
\hline
\end{tabular}
}
}\\

\end{table}

\end{document}

using pdflatex.

I am getting the following errors during compilation:

Overfull \hbox (6.71255pt too wide) in paragraph at lines 28--29
[][] 

Underfull \hbox (badness 10000) in paragraph at lines 28--29

I am not able to figure out the reason here!

5
  • 1
    Schweinebacke's answer explained why the error messages but the main problem is not that you left some unnecessary spaces or break lines, it is all the unnecessary \resizebox and \subfloat wrappers. A centered tabular is more that enough, or alternatively, only a tabular*, tabularx or tabulary, if you are obsessed about make the with of the table equal to \linewidth. I will not say that use \hline it is also a problem, but I would change it for booktabs commands. – Fran Jan 25 '17 at 9:29
  • 1
    scaling tables is a really bad idea!!! you would not justify a paragraph of text by arbitrarily scaling the font to make the lines full width, why do it if the text is in a table, it will make the document look horribly inconsistent with font sizes and widths of lines varying in uncontrollable ways. – David Carlisle Jan 25 '17 at 9:45
  • @Fran, I am using subfloat because there are more than 1 tabular in my original table, and are expected to be placed 1 below another. I stripped them down to 1 tabular for simplicity. I don't know of any other way to do put multiple tables inside 1 big table without using subfloats. Any suggestions? (I am new to latex). I was using \resizebox because it looked better than left aligned table. Apparently all I needed to do instead was use "\centering". So that is fixed now – vervenumen Jan 25 '17 at 10:03
  • @vervenumen: Maybe it would help to read something like LaTeX for Complete Novices. It shows not only the usage of \centering in table. But also how to use minipage or subfigure. – Schweinebacke Jan 25 '17 at 10:23
  • @vervenumen. On table below another without sub-captions? Then a blank line between the two tabulars is enough. About subfigures positions and captions there are several alternatives: run texdoc subfig, texdoc subcaption and texdoc subfloats (o search this packages in CTAN) for some information. – Fran Jan 25 '17 at 10:39
3

The overfull \hbox is because of the white spaces from the line endings. You should comment such line endings.

The underfull \hbox is because of the \\ that should never be used to fake a paragraph:

\documentclass{article}
\usepackage{graphicx,multirow,subfig,hyperref}% Load only used packages

% settings moved to preamble
\clubpenalty=10000 
\widowpenalty = 10000

\begin{document}

\begin{table}
%\newcommand{\tabcolwidth}[1]{\parbox[c]{3cm}{\centering #1}}
\renewcommand\multirowsetup{\centering}
\caption{caption}

\subfloat{%
  \resizebox{1.0\linewidth}{!}{%
    \begin{tabular}{lrrrr}
      \hline
      \multirow{2}{*}{A} & \multicolumn{4}{c}{B} \\
                         & $20 \%$ & $40 \%$ & $60 \%$ & $80 \%$ \\
      \hline
      Alg1 & $48.21$ & $48.64$ & $51.13$ & $52.46$ \\
      Alg2 & $42.72$ & $46.31$ & $48.56$  & $51.64$ \\
      \hline
    \end{tabular}%
  }%
}

\end{table}
7
  • Now I understand what led to those errors, but don't understand why they happened. Why do white spaces from line endings cause the overfull error? Why should "\\" not be used to fake a paragraph? " – vervenumen Jan 25 '17 at 9:29
  • @vervenumen TeX does not distinguish between single line endings and other white spaces. And white spaces in horizontal mode are a blank. So you have additional blanks. And \\ are not paragraphs but context depending, e.g. hard breaks, so you should not use them to fake paragraphs. Use an empty line or \par to make a paragraph. You may get a lot of problems otherwise not not only underfull \hbox. See tex.stackexchange.com/questions/66495, tex.stackexchange.com/questions/136942, tex.stackexchange.com/questions/82664. – Schweinebacke Jan 25 '17 at 9:39
  • @vervenumen would you expect \fbox{ a } to be wider than \fbox{a}? It is, whether the white space is a space or a newline, and \resizebox is the same, except the boundary is invisible. – David Carlisle Jan 25 '17 at 9:43
  • 2
    @vervenumen by default it is if you go one two and a line break happens then the space is dropped at the linebreak, and if no linebreak happens you only get one space but if you do \mbox{one } two then if no line break happens you get two spaces and the first one is never dropped. this is exactly what you have done here, it isn't that latex can not accommodate white space it is that it follows instructions in the file, even when they are wrong. – David Carlisle Jan 25 '17 at 9:56
  • 1
    @vervenumen The problem isn't to manage one more space, the problem is to manage a box which explicit line width (\residebox{1.0\linewidth}) and an additional space. This is like dropping an orange into a jug that has already been filled with water: It becomes overfull. – Schweinebacke Jan 25 '17 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.