我正在使用以下代码制作表格:
\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}
但是出现以下错误 \hbox (124.69516pt 太宽),因此表格无法显示。
编辑:整个代码,以便 Phelype Oleinik 可以检查它:
\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}
如果有相关性的话,我正在使用 sharelatex.com。
答案1
“过满的水平盒子”基本上意味着有东西超出了文本边距,在本例中是表格。要挽救它,您可以增加 TeX 允许的外推限制(不推荐),或缩小错误的行(表格)以适合边距。
您的表格太宽了,因为它有标题。我使用\tblmultiline
命令将它们拆分成多行以适合页面:
\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}