我正在使用下面的代码,
\begin{table}
\caption{RFID Operating Frequency}
\label{tab:2_3}
\centering
\begin{tabular}{ |p{3cm}|p{2cm}|p{2cm}|p{3cm}| }
\hline
\Centering \textbf{Frequency Band} & \Centering \textbf{Read Distance} & \Centering \textbf{Data Speed} & \Centering \textbf{Application} \\ \hline
\Centering Low Frequency \\ (120–150 kHz) & Hours & Days & Years \\ \hline
\Centering High Frequency \\ (13.56 MHz) & Very complex & Complex & Simple \\ \hline
\Centering Ultra-High Frequency \\ (868-928 MHz) & QPSK & FSK, GMSK & BPSK, O- QPSK \\ \hline
\Centering Microwave \\ (2.45-5.8 GHz) & Microwave & Microwave & Microwave \\ \hline
\end{tabular}
\end{table}
获取输出结果,其中某些新行的表格边距在右侧缺失,
我如何才能修复表格边距以适应新行?
答案1
在...的帮助下makecell
:
\documentclass{article}
\usepackage{array}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}
\begin{document}
\begin{table}
\caption{RFID Operating Frequency}
\label{tab:2_3}
\setlength{\tabcolsep}{5pt}
\centering
\begin{tabular}{ |l|l|l|l| }
\hline
\thead{Frequency Band} & \thead{Read Distance} & \thead{Data Speed} & \thead{Application} \\ \hline
\makecell[ct]{Low Frequency \\ (120–150 kHz)} & Hours & Days & Years \\ \hline
\makecell[ct]{High Frequency \\ (13.56 MHz)} & Very complex & Complex & Simple \\ \hline
\makecell[ct]{Ultra-High Frequency \\ (868-928 MHz)} & QPSK & FSK, GMSK & BPSK, O- QPSK \\ \hline
\makecell[ct]{Microwave\\ (2.45-5.8 GHz)} & Microwave & Microwave & Microwave \\ \hline
\end{tabular}
\end{table}
\end{document}
答案2
我将按如下方式重新设计您的表格:
即:我根本不会使用垂直线!
在 MWE 中使用包caption
(用于表格标题)、booktabs
用于表格中的水平规则)、makecell
用于单元格格式化的命令和\thead
用于在行中插入额外垂直空间的宏:makecell
\makegapredcell
\documentclass{article}
\usepackage[skip=1ex, font=small, labelfont=bf]{caption}
\usepackage{booktabs, makecell}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\usepackage{siunitx}
\begin{document}
\begin{table}[ht]
\caption{RFID Operating Frequency}
\label{tab:2_3}
\centering
\setcellgapes{3pt}
\makegapedcells
\begin{tabular}{@{} c *{3}{l} @{} }
\toprule
\thead[l]{Frequency Band} & \thead[l]{Read Distance} & \thead[l]{Data Speed} & \thead[l]{Application} \\
\midrule
\makecell{Low Frequency \\ (\SIrange{120}{150}{kHz})}
& Hours & Days & Years \\
\makecell{High Frequency \\ (\SI{13.56}{MHz})}
& Very complex & Complex & Simple \\
\makecell{Ultra-High Frequency \\ (\SIrange{868}{928}{MHz})}
& QPSK & FSK, GMSK & BPSK, O- QPSK \\
\makecell{Microwave \\ (\SIrange{2.45}{5.8}{GHz})}
& Microwave & Microwave & Microwave \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
如果使用代替标准的{NiceTabular}
,即使在不完整的行中,垂直规则也不会被破坏。nicematrix
{tabular}
\documentclass{article}
\usepackage{nicematrix}
\usepackage{ragged2e}
\begin{document}
\begin{table}
\caption{RFID Operating Frequency}
\label{tab:2_3}
\centering
\begin{NiceTabular}{ |p{3cm}|p{2cm}|p{2cm}|p{3cm}| }
\hline
\Centering \textbf{Frequency Band} & \Centering \textbf{Read Distance} & \Centering \textbf{Data Speed} & \Centering \textbf{Application} \\ \hline
\Centering Low Frequency \\ (120–150 kHz) & Hours & Days & Years \\ \hline
\Centering High Frequency \\ (13.56 MHz) & Very complex & Complex & Simple \\ \hline
\Centering Ultra-High Frequency \\ (868-928 MHz) & QPSK & FSK, GMSK & BPSK, O- QPSK \\ \hline
\Centering Microwave \\ (2.45-5.8 GHz) & Microwave & Microwave & Microwave \\ \hline
\end{NiceTabular}
\end{table}
\end{document}
然而,OP期望的输出可能更像下面的代码(使用 的工具nicematrix
)。
\documentclass{article}
\usepackage{caption}
\usepackage{nicematrix}
\begin{document}
\begin{table}
\caption{RFID Operating Frequency}
\label{tab:2_3}
\centering
\begin{NiceTabular}{clll}[hvlines,cell-space-limits=2pt]
\RowStyle{\bfseries}
Frequency Band & \Block[c]{}{Read Distance} & \Block[c]{}{Data Speed} & \Block[c]{}{Application} \\
\Block{}{Low Frequency \\ (120–150 kHz)} & Hours & Days & Years \\
\Block{}{High Frequency \\ (13.56 MHz)} & Very complex & Complex & Simple \\
\Block{}{Ultra-High Frequency \\ (868-928 MHz)} & QPSK & FSK, GMSK & BPSK, O- QPSK \\
\Block{}{Microwave \\ (2.45-5.8 GHz)} & Microwave & Microwave & Microwave \\
\end{NiceTabular}
\end{table}
\end{document}