我使用tabularx
自动换行功能在表格中换行。这是我的代码。
\begin{table}[h]
\caption{A table}
\begin{tabularx}{\textwidth}{|l|X|}
\hline
\multicolumn{1}{|c|}{\textbf{Term}} & \multicolumn{1}{c|}{\textbf{Description}} \\
\hline
key1 & A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. \\
\hline
\end{tabularx}
\end{table}
在 中可以工作,\documentclass[a4paper]{article}
但在 中失败\documentclass[conference]{IEEEtran}
(两列)。结果如下。
答案1
很简单:\textwidth
用替换\linewidth
。我借此机会改善了表格行的垂直间距,并提出了一种没有垂直线的解决方案,在许多人看来,这种解决方案看起来更好:
\documentclass{ieeetran}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{booktabs, caption, tabularx, makecell}
\renewcommand\theadfont{\bfseries}
\setcellgapes{4pt}
\begin{document}
\lipsum[1]
\begin{table}[h]
\caption{A table}
\makegapedcells
\begin{tabularx}{\linewidth}{|l|X|}
\hline
\multicolumn{1}{|c|}{\textbf{Term}} & \multicolumn{1}{c|}{\textbf{Description}} \\
\hline
key1 & A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. \\
\hline
\end{tabularx}
\end{table}
\lipsum[2-5]
\begin{table}[h]
\caption{A table}
\begin{tabularx}{\linewidth}{lX}
\toprule
\thead{Term} & \thead{Description} \\
\midrule
key1 & A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. \\
\bottomrule
\end{tabularx}
\end{table}
\lipsum[6]
\end{document}
答案2
你可以得到这个:
\documentclass[conference]{IEEEtran}
\usepackage{tabularx,lipsum}
\begin{document}
\lipsum[1-2]
\begin{table}[h]
\renewcommand{\arraystretch}{1.2}
\caption{A table}
\begin{tabularx}{\linewidth}{|l|X|}
\hline
\multicolumn{1}{|c|}{\textbf{Term}} & \multicolumn{1}{c|}{\textbf{Description}} \\
\hline \hline
key1 & A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. \\
\hline
\end{tabularx}
\end{table}
\lipsum[3-8]
\end{document}
使用tabularx
能够利用所有可用宽度。l
由于第一列较短,因此设置为 ,另一列设置X
为 在剩余可用宽度内自动分页。在双列文档中\linewidth
不等于使用第一列。\textwidth
注意:您可以使用它,booktabs
因为它更漂亮,但是,我使用的风格在 IEEE 期刊和会议中最常见。