1

I'm making a table with the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\title{Answer}
\author{That's me}
\date{March 2018}
\setlength{\parindent}{0pt}
\begin{document}

\maketitle
\begin{table}[h!]
\centering
\begin{tabular}{||c c c c c||} 
 \hline
 Instruction & Mode & \#cycles without prefetch & \#cycles with prefetch & \#memory accesses \\ [0.5ex] 
 \hline\hline
ADD $R_i$ expr & 6 & 87837 & 787 & pototo \\ 
LOAD $R_i$ [expr] & 7 & 78 & 5415 & pototo\\
XOR $R_i$ [expr] & 545 & 778 & 7507 & pototo\\
STOR $R_i$ [expr] & 545 & 18744 & 7560 & pototo \\
BEQ disp (not taken) & 88 & 788 & 6344 & pototo \\ 
BEQ disp (taken) & 88 & 788 & 6344 & pototo\\ [1ex] 
\hline
\end{tabular}
\caption{Table to test captions and labels}
\label{table:1}
\end{table}
\end{document}

But getting the following error \hbox (124.69516pt too wide) and therefore the table isn't showing.

I checked these two questions but the solution didn't work for me. This one and This one

Edit: the whole code so that Phelype Oleinik can check it:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\title{Answer}
\author{That's me}
\date{March 2018}
\setlength{\parindent}{0pt}
\newcommand{\tblmultiline}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\begin{document}
\pagenumbering{gobble}

\maketitle

\textbf{2.1.b)} normal text
\\

\textbf{2.1.c)} Normal text
\\

\textbf{2.1.d)} Normal text and some code. Here's the code: \\

SigmaA $<-$ IR.val(Bbus) \\
\{ SigA = IR.val \} \\ 
SigmaR $<-$ RAM[SigmaA] \\
\{ SigA = IR.val, SigR = RAM \} \\
SigmaW, CC $<-$ RA(Abus) + SigmaR(Bbus), ALU.cc \\
\{ SigA = IR.val, SigR = RAM[IR.val], CC = ALU.cc, SigW = RA+RAM[IR.val]\} \\
RAM[SigmaA] $<-$ SigmaW \\
\{RAM[IR.val] = RAM[IR.val] + RA \} \\


\textbf{2.3.c)} 


\begin{table}[h!]
\centering
\begin{tabular}{||c c c c c||} 
 \hline
 Instruction & Mode & \tblmultiline{\#cycles\\without\\prefetch} &     \tblmultiline{\#cycles\\with\\prefetch} & \tblmultiline{\#memory\\accesses} \\    [0.5ex]
 \hline\hline
ADD $R_i$ expr & 6 & 87837 & 787 & pototo \\ 
LOAD $R_i$ [expr] & 7 & 78 & 5415 & pototo\\
XOR $R_i$ [expr] & 545 & 778 & 7507 & pototo\\
STOR $R_i$ [expr] & 545 & 18744 & 7560 & pototo \\
BEQ disp (not taken) & 88 & 788 & 6344 & pototo \\ 
BEQ disp (taken) & 88 & 788 & 6344 & pototo\\ [1ex] 
\hline
\end{tabular}
\caption{Table to test captions and labels}
\label{table:1}
\end{table}

\end{document}

I'm using sharelatex.com if that's relevant at all.

2
  • 1
    An overfull hbox mean that something is extrapolating the document margins. In this case, your table is too wide because of its headers. Commented Mar 19, 2018 at 18:39
  • @PhelypeOleinik how do i fix that?
    – user148199
    Commented Mar 19, 2018 at 18:40

1 Answer 1

1

An "overfull hbox" basically means that something is extrapolating the text margins, in this case, the table. To save it you can increase the limit of extrapolation that TeX allows (not recommended), or shrink the faulty line (table) to fit in the margins.

Your table is too wide because of its headers. I used a \tblmultiline comman to split them into multiple lines to fit in the page:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\title{Answer}
\author{That's me}
\date{March 2018}
\setlength{\parindent}{0pt}
\newcommand{\tblmultiline}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\begin{document}
\pagenumbering{gobble}

\maketitle
\begin{table}[h!]
\centering
\begin{tabular}{||c c c c c||} 
 \hline
 Instruction & Mode & \tblmultiline{\#cycles\\without\\prefetch} & \tblmultiline{\#cycles\\with\\prefetch} & \tblmultiline{\#memory\\accesses} \\[0.5ex]
 \hline\hline
ADD $R_i$ expr & 6 & 87837 & 787 & pototo \\ 
LOAD $R_i$ [expr] & 7 & 78 & 5415 & pototo\\
XOR $R_i$ [expr] & 545 & 778 & 7507 & pototo\\
STOR $R_i$ [expr] & 545 & 18744 & 7560 & pototo \\
BEQ disp (not taken) & 88 & 788 & 6344 & pototo \\ 
BEQ disp (taken) & 88 & 788 & 6344 & pototo\\ [1ex] 
\hline
\end{tabular}
\caption{Table to test captions and labels}
\label{table:1}
\end{table}
\end{document}
7
  • I copied your solution but it still doesn't work. Am i missing something?
    – user148199
    Commented Mar 19, 2018 at 18:47
  • 1
    @AbdulMalekAltawekji What doesn't work? I compiled the exmaple code and there are no warnings. If you're using the table in a large document, did you remember to copy the line that says \newcommand{\tblmultiline}...? Commented Mar 19, 2018 at 18:49
  • Yes i did but oddly enough the table is not visible but i'm getting no warnings
    – user148199
    Commented Mar 19, 2018 at 18:50
  • 1
    @AbdulMalekAltawekji Very strange... Can you share the whole code you're using for me to see why the table isn't showing? If not, try removing parts of the code until there is enough to show the problem. Commented Mar 19, 2018 at 18:54
  • 1
    @AbdulMalekAltawekji The definition of \tblmultiline in the code you posted was missing a ]. I edited your question to fix it. Other than that, it works fine. Here is the result. Commented Mar 19, 2018 at 19:06

You must log in to answer this question.