} 太多。Latex 错误:\begin{document} 以 \end{table} 结束。EXTRA \endgroup

} 太多。Latex 错误:\begin{document} 以 \end{table} 结束。EXTRA \endgroup

在 main.tex 中

%  $Description: Thesis
%  $Author: xxx $
%  $Date: xxx  $
%  $Revision: 0.0 $

\documentclass[11pt]{book}
\usepackage{times}
\usepackage{epsfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{algorithm2e}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{blindtext}
\graphicspath{{Figures/}{./}} % To include images in other directories
%\usepackage{setspace}

\long\def\symbolfootnote[#1]#2{\begingroup%
\def\thefootnote{\fnsymbol{footnote}}\footnote[#1]{#2}\endgroup}
\renewcommand{\baselinestretch}{1.2}
\onecolumn
%--------------------------------------------------------

\begin{document}

在 chapter2.tex 中

\begin{table}[t]
\begin{center}
\begin{tabular}{ |c|c|c| } 
\hline
\textbf{Parameters}&
\textbf{Ground WSN}& 
\textbf{Underwater WSN}\\ \hline
Communication Modality & Radio waves & Acoustic waves  \\ \hline
Channel Propagation Speed & 300,000,000 m/s & 1,500 m/s \\ \hline
Transmission Range & 10 to 100 m & Up to 10 Km \\ \hline
Energy consumption & Low comparatively & High comparatively \\ \hline
Memory capacity  & Small  & Large \\ \hline
Cost & Cheap & Expensive \\ \hline
Frequency & 908 to 928 MHz & 10 Hz to 100 KHz \\ \hline
Node Mobility & Application based & Mobile \\ \hline
Node Density & Dense & Sparse \\ \hline
Link Reliability & Application based & Low \\ \hline
Link Stability & Stable & Unstable \\ \hline
Path  Loss & Low & High\\ \hline
Noise Impact & Low & High \\ \hline
Data Flow Mode & Full Duplex & Half Duplex \\ \hline
Flow and Error Control Protocol & Selective Repeat ARQ or Go-Back-N ARQ & Stop-and-Wait ARQ \\
\end{tabular}
\label{tab:table:1}
\caption{Difference between WSN and UWSN}
\end{center}
\end{table}

答案1

  • 从你的代码片段中不可能编写 MWE(最小工作示例),这将是你的问题的根源
  • 错误发生在文档中表格代码片段之外的某个地方

一些题外话:

  • 表格宽度大于`\text 宽度,因此表格突出右文本区域边框
  • 为了防止这种情况,您需要规定列宽,例如p{\dimexpr\linewidth/3-2\tabcolsep}<width>}或更简单地使用xtabulartabularray允许自动计算列宽的包。
  • 通过使用tabularrray包表代码简短而清晰
  • 对于数量的书写,我建议使用siunitx
\documentclass[11pt]{book}

%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage[T1]{fontenc}
\usepackage[english]{babel}

\usepackage{newtxtext, newtxmath}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}    % it load siunitx package

\begin{document}
    \begin{table}[ht]
    \sisetup{group-separator={,}}
\begin{tblr}{hlines, vlines,
             colspec = {X[l, m] X[l, m] X[l]},
              row{1} = {font=\bfseries}
             }
Parameters
        &   Ground WSN
                &   Underwater WSN      \\
Communication Modality 
        & Radio waves
                & Acoustic waves        \\
    Channel Propagation Speed
        & \qty{300 000 000}{\metre\per\second}
                & \qty{1 500}{\metre\per\second}    \\
Transmission Range 
        & \qtyrange{10}{100}{\metre}
                & Up to \qty{10}{\kilo\metre}       \\
Energy consumption 
        & Low comparatively
                & High comparatively    \\
Memory capacity  
        & Small & Large                 \\
Cost    & Cheap & Expensive             \\ 
Frequency 
        & \qtyrange{908}{928}{\mega\hertz}
                & \qty{10}{\hertz} to \qty{100}{\kilo\hertz}    \\
Node Mobility 
        & Application based 
                & Mobile                \\ 
Node Density 
        & Dense & Sparse                \\ 
Link Reliability 
        & Application based 
                & Low                   \\
Link Stability 
        & Stable & Unstable             \\ 
Path  Loss 
        & Low   & High                  \\ 
Noise Impact 
        & Low   & High                  \\
Data Flow Mode 
        & Full Duplex 
                & Half Duplex           \\ 
Flow and Error Control Protocol 
        & Selective Repeat ARQ or Go-Back-N ARQ 
                & Stop-and-Wait ARQ     \\
\end{tblr}
\caption{Difference between WSN and UWSN}
\label{tab:table:1}
    \end{table}
\end{document}
\end{document} 

在此处输入图片描述

(红线表示页面布局)

如果你出于某些原因坚持认为表格单元格中的文本居中,那么对于列规范使用colspec = {X[c, m] X[c, m] X[c]}。那么得到的表格是:

在此处输入图片描述

答案2

表格的主要问题是无法保证其宽度适合文本块。事实上,使用 LaTeX 默认边距设置,表格太宽了。为了解决这个问题,我建议您使用环境tabularx并允许在前两列自动换行。

另外两个建议:(a)为了使表格看起来更加开放和吸引人,请删除所有垂直规则和大多数水平规则。(b)我建议左对齐而不是居中对齐单元格内容。

如果您希望能够交叉引用表,则语句\label必须位于\caption语句之后,而不是之前。

我已在下面的代码中插入进一步的建议和评论作为评论。

在此处输入图片描述

\documentclass[11pt]{book}
%%%\usepackage{epsfig}   % superseded by 'graphicx' package
\usepackage{amsmath}
\usepackage{amssymb}
%%%\usepackage{latexsym} % superseded by 'amssymb' package
\usepackage{graphicx}
\graphicspath{{Figures/}{./}} % To include images in other directories
\usepackage{multirow}
\usepackage{algorithm2e}
%%%\usepackage{graphicx} % don't load packages more than once
%%%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
%%%\usepackage{times} % 'times' package is obsolete
\usepackage{newtxtext,newtxmath} % Times Roman-clone text and math fonts

%%%\usepackage{blindtext} % not needed here

\usepackage{setspace}
\setstretch{1.2}
%% Don't modify the low-level \baselinestretch parameter directly:
%%%\renewcommand{\baselinestretch}{1.2} 

%% is the following really needed?
\long\def\symbolfootnote[#1]#2{\begingroup%
\def\thefootnote{\fnsymbol{footnote}}\footnote[#1]{#2}\endgroup}


% New code:
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{tabularx} % for 'tabularx' env. and 'X' column type
%% 'L' col. type allows both automatic line breaking and hanging indentation:
\newcolumntype{L}{>{\raggedright\hangafter=1\hangindent=1em}X}

%%%\onecolumn % really??

\begin{document}

\begin{table}[t]
%%%\begin{center} % not appropriate
%%%\centering     % not needed
\begin{tabularx}{\textwidth}{@{} LL l @{}}   %%%{ |c|c|c| } 
\toprule % Use fewer, but well-spaced horizontal rules
%% No need for vulgar bold-facing in header cells:
%\textbf{Parameters}&\textbf{Ground WSN}& \textbf{Underwater WSN}
Parameters & Ground WSN & Underwater WSN \\
\midrule
%% I've commented out all 14 [!] remaining \hline directives:
Communication modality & Radio waves & Acoustic waves  \\ %\hline
Channel propagation speed & 300,000,000 m/s & 1,500 m/s \\ %\hline
Transmission range & 10 to 100 m & Up to 10 km \\ %\hline
Energy consumption & Low comparatively & High comparatively \\ \addlinespace %\hline
Memory capacity  & Small  & Large \\ %\hline
Cost & Cheap & Expensive \\ %\hline
Frequency & 908 to 928 MHz & 10 Hz to 100 KHz \\ %\hline
Node mobility & Application based & Mobile \\ \addlinespace %\hline
Node density & Dense & Sparse \\ %\hline
Link reliability & Application based & Low \\  %\hline
Link stability & Stable & Unstable \\ %\hline
Path loss & Low & High\\ \addlinespace %\hline
Noise impact & Low & High \\ %\hline
Data flow mode & Full duplex & Half duplex \\ %\hline
Flow and error control protocol & Selective Repeat ARQ or Go-Back-N ARQ & Stop-and-Wait ARQ \\
\bottomrule
\end{tabularx}

%%% ALWAYS place \label after, ot before, \caption:
\caption{Differences between WSN and UWSN} \label{tab:table:1}
%%%\end{center}
\end{table}

\end{document}

相关内容