表格 - 调整表格大小和自动换行

表格 - 调整表格大小和自动换行

我有下表。

\begin{table}[]
\centering
\resizebox{\textwidth}{!}{
\begin{tabularx}{\textwidth}{|X|X|X|X|X|X|X|X|X|}
\hline
\textbf{Cache Configuration} &
  \textbf{Access Latency (ns)} &
  \textbf{Overhead} &
  \textbf{Dynamic Read Energy (nJ)} &
  \textbf{Overhead} &
  \textbf{Leakage Power (mW)} &
  \textbf{Overhead} &
  \textbf{Area (mm2)} &
  \textbf{Overhead} \\ \hline
Conventional Cache (1MB)           & 1.3125 &      & 0.3295 &      & 221.796  &      & 3.4085  &      \\ \hline
Conventional Cache (8MB)           & 2.7504 &      & 0.8605 &      & 1641.11  &      & 18.7754 &      \\ \hline
Frequency Table (FT)               & 0.4129 &      & 0.0008 &      & 2.4785   &      & 0.0296  &      \\ \hline
Precompression Table (PT)          & 0.6353 &      & 0.0014 &      & 4.9366   &      & 0.0788  &      \\ \hline
Mapping Table (MT)                 & 0.0927 &      & 0.0011 &      & 0.3396   &      & 0.0032  &      \\ \hline
Overflow Mapping Table             & 0.3394 &      & 0.0020 &      & 4.5186   &      & 0.038   &      \\ \hline
Precompression-enabled Cache (1MB) & 2.2873 & 74\% & 0.4178 & 26\% & 273.539  & 23\% & 3.9191  & 15\% \\ \hline
Precompression-enabled Cache (8MB) & 3.7251 & 35\% & 0.9489 & 10\% & 1692.853 & 3\%  & 19.2859 & 5\%  \\ \hline
\end{tabularx}
}
\caption{Access Latency, Energy, Power and Area Overheads of Precompression logic and Precompression-enabled caches.}
\label{table:precompression-overhead}
\end{table}

表输出

我尝试过不同的方法,但似乎都行不通。我希望表格适合页面,并自动换行,不会用连字符断开单词(可能 Overhead 列除外)。

答案1

第一的关闭,请注意\resizebox{\textwidth}{...}“包装器”没有任何用处,因为命令的第二个参数的宽度相等\textwidth。事实上,你设置包装器的方式实际上有点适得其反。为什么?你的代码如下:

\resizebox{\textwidth}{!}{
\begin{tabularx}{\textwidth}{|X|X|X|X|X|X|X|X|X|}
...
\end{tabularx}
}

那么你可能会问,问题到底是什么?事实上你没有终止线路

\resizebox{\textwidth}{!}{

带有%(注释)符号。因此,总宽度所管辖的材料的\resizebox不仅仅是\textwidth而且\textwidth加上 1 个单词间距。正确的写指令方式如下:

\resizebox{\textwidth}{!}{%

然而,正如上面所论证的,\resizebox包装器一开始就是多余的,应该被省略。

第二,我建议您继续使用tabularx环境,但“开销”列的宽度应小于其他列。在下面的解决方案中,四个“开销”列比其他四个数据列窄 40%。设置 类型的可变宽度列时X,基本规则是相对宽度之和——4*1.25+4*0.75——必须等于 类型的列数X——此处为:8。

第三,我会尽力给它一个更加开放的“外观”,主要是通过省略所有垂直规则和使用更少但间距适当的水平规则。

最后,我会将第一列左对齐,并将所有 8 个数据列居中设置。


以下是建议的修改和相关的屏幕截图:

在此处输入图片描述

\documentclass{article}
\usepackage[letterpaper,hmargin=1in]{geometry} % set page parameters suitably
\usepackage{tabularx,ragged2e,booktabs}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
% set up a modified, i.e., centered version of the "X" column type:
\newcolumntype{C}[1]{>{\Centering\arraybackslash%
     \hsize=#1\hsize\linewidth=\hsize\hspace{0pt}}X}

% determine width and column type of first column:
\newlength\mylen
\settowidth\mylen{enabled Cache (8MB)} 
\newcolumntype{M}{>{\RaggedRight}m{\mylen}}

\begin{document}
\begin{table}
\setlength\tabcolsep{3pt} % default: 6pt
\begin{tabularx}{\textwidth}{@{} M *{4}{C{1.25}C{0.75}} @{}}
\toprule
  \textbf{Cache Configuration} &
  \textbf{Access Latency} (ns) &
  \textbf{Overhead} &
  \textbf{Dynamic Read Energy} (nJ) &
  \textbf{Overhead} &
  \textbf{Leakage Power} (mW) &
  \textbf{Overhead} &
  \textbf{Area} (mm\textsuperscript{2}) &
  \textbf{Overhead} \\ 
\midrule
Conventional Cache (1MB)           & 1.3125 &      & 0.3295 &      & 221.796  &      & 3.4085  &      \\ \addlinespace
Conventional Cache (8MB)           & 2.7504 &      & 0.8605 &      & 1641.11  &      & 18.7754 &      \\ \addlinespace
Frequency Table (FT)               & 0.4129 &      & 0.0008 &      & 2.4785   &      & 0.0296  &      \\ \addlinespace
Precompression Table (PT)          & 0.6353 &      & 0.0014 &      & 4.9366   &      & 0.0788  &      \\ \addlinespace
Mapping Table (MT)                 & 0.0927 &      & 0.0011 &      & 0.3396   &      & 0.0032  &      \\ \addlinespace
Overflow Mapping Table             & 0.3394 &      & 0.0020 &      & 4.5186   &      & 0.038   &      \\ \addlinespace
Precompression-enabled Cache (1MB) & 2.2873 & 74\% & 0.4178 & 26\% & 273.539  & 23\% & 3.9191  & 15\% \\ \addlinespace
Precompression-enabled Cache (8MB) & 3.7251 & 35\% & 0.9489 & 10\% & 1692.853 & 3\%  & 19.2859 & 5\%  \\ 
\bottomrule
\end{tabularx}
\caption{Access Latency, Energy, Power and Area Overheads of Precompression logic and Precompression-enabled caches.}
\label{table:precompression-overhead}
\end{table}
\end{document}

答案2

根据对文档布局的猜测。避免重叠的一种方法是使用旋转的列标题:

\documentclass[a4paper,fleqn,10pt,oneside]{book}
\usepackage{geometry}

\usepackage{siunitx}
\usepackage{rotating}
\usepackage{makecell, multirow, tabularx}
\renewcommand\theadfont{\small\footnotesize}
\renewcommand\theadgape{}

\begin{document}
\begin{table}[htb]
\centering
\small
\setlength\tabcolsep{4pt}
\setcellgapes{3pt}
\makegapedcells
\settowidth\rotheadsize{\theadfont Dynamic Read} 
\begin{tabularx}{\textwidth}{|>{\raggedright}X|S[table-format=1.4]|c|
                                S[table-format=1.4]|c|
                                S[table-format=4.4]|c|
                                S[table-format=2.4]|c|}
\hline
\thead{Cache\\ Configuration} &
  \rothead{Access Latency (ns)} &
  \rothead{Overhead} &
  \rothead{Dynamic Read Energy (nJ)} &
  \rothead{Overhead} &
  \rothead{Leakage Power (mW)} &
  \rothead{Overhead} &
  \rothead{Area (mm2)} &
  \rothead{Overhead} \\ \hline
Conventional Cache (1MB)           & 1.3125 &      & 0.3295 &      & 221.796  &      & 3.4085  &      \\ \hline
Conventional Cache (8MB)           & 2.7504 &      & 0.8605 &      & 1641.11  &      & 18.7754 &      \\ \hline
Frequency Table (FT)               & 0.4129 &      & 0.0008 &      & 2.4785   &      & 0.0296  &      \\ \hline
Precompression Table (PT)          & 0.6353 &      & 0.0014 &      & 4.9366   &      & 0.0788  &      \\ \hline
Mapping Table (MT)                 & 0.0927 &      & 0.0011 &      & 0.3396   &      & 0.0032  &      \\ \hline
Overflow Mapping Table             & 0.3394 &      & 0.0020 &      & 4.5186   &      & 0.038   &      \\ \hline
Precompression-enabled Cache (1MB) & 2.2873 & 74\% & 0.4178 & 26\% & 273.539  & 23\% & 3.9191  & 15\% \\ \hline
Precompression-enabled Cache (8MB) & 3.7251 & 35\% & 0.9489 & 10\% & 1692.853 & 3\%  & 19.2859 & 5\%  \\ \hline
\end{tabularx}

\caption{Access Latency, Energy, Power and Area Overheads of Precompression logic and Precompression-enabled caches.}
\label{table:precompression-overhead}
\end{table}
\end{document}

在此处输入图片描述

或者当\textwidth较小时:

\documentclass[a4paper,fleqn,10pt,oneside]{book}
\usepackage{siunitx}
\usepackage{rotating}
\usepackage{makecell, multirow, tabularx}
\renewcommand\theadfont{\small\footnotesize}
\renewcommand\theadgape{}

\begin{document}
\begin{table}[htb]
\centering
\small
\setlength\tabcolsep{3pt}
\setcellgapes{3pt}
\makegapedcells
\settowidth\rotheadsize{\theadfont Dynamic Read} 
\begin{tabularx}{\textwidth}{|>{\raggedright}X|
                                S[table-format=1.4]|c|
                                S[table-format=1.4]|c|
                                S[table-format=4.4]|c|
                                S[table-format=2.4]|c|}
\hline
\thead{Cache\\ Configuration} &
  \rothead{Access Latency (ns)} &
  \rothead{Overhead} &
  \rothead{Dynamic Read Energy (nJ)} &
  \rothead{Overhead} &
  \rothead{Leakage Power (mW)} &
  \rothead{Overhead} &
  \rothead{Area (mm2)} &
  \rothead{Overhead} \\ \hline
Conventional Cache (1MB)           & 1.3125 &      & 0.3295 &      & 221.796  &      & 3.4085  &      \\ \hline
Conventional Cache (8MB)           & 2.7504 &      & 0.8605 &      & 1641.11  &      & 18.7754 &      \\ \hline
Frequency Table (FT)               & 0.4129 &      & 0.0008 &      & 2.4785   &      & 0.0296  &      \\ \hline
Precompression Table (PT)          & 0.6353 &      & 0.0014 &      & 4.9366   &      & 0.0788  &      \\ \hline
Mapping Table (MT)                 & 0.0927 &      & 0.0011 &      & 0.3396   &      & 0.0032  &      \\ \hline
Overflow Mapping Table             & 0.3394 &      & 0.0020 &      & 4.5186   &      & 0.038   &      \\ \hline
Precompression-enabled Cache (1MB) & 2.2873 & 74\% & 0.4178 & 26\% & 273.539  & 23\% & 3.9191  & 15\% \\ \hline
Precompression-enabled Cache (8MB) & 3.7251 & 35\% & 0.9489 & 10\% & 1692.853 & 3\%  & 19.2859 & 5\%  \\ \hline
\end{tabularx}

\caption{Access Latency, Energy, Power and Area Overheads of Precompression logic and Precompression-enabled caches.}
\label{table:precompression-overhead}
\end{table}
\end{document}

在此处输入图片描述

答案3

这是一个使用包的可能解决方案表格代替表格型。我还加载了 babel 以自动连字符 'Overhead'。此外,我还加载了几何学,因为我假设您的实际文档中有更合理的边距。字体大小减小到\footnotesize,然后您就会得到一个可读的表格,它适合合理的边距。

当然,我建议使用以下方式设置表格书签并且没有垂直线,见下面的示例 1 和 3。百分号 (%) 应从列移至标题。

(更新的) 示例 1 使用固定宽度x-columns 与 tabular* 结合使用。标题设置在嵌套的表格中,并且使用 手动设置换行符\\。您可以使用\parbox代替表格。标题的字体大小减少了两个等级,为\footnotesize,其余表格的文本和图形采用正常字体大小(10 pt)。我已将标题对齐到底部,因为这符合我所在地区的建议。

如果你有权重组表格,我建议你将四个顶部列移动到两个新的并描述开销所指的内容(比较传统缓存和启用预压缩的缓存?)

示例 1 - 表格*

在此处输入图片描述

\documentclass[UKenglish]{article}
\usepackage{array, tabulary, booktabs, lmodern}
\usepackage{babel, caption}
\usepackage{geometry}



% Multi-line left-aligned text with manual line breaks.
% The base line of the whole is at the top row.
\newcommand*{\tstack}[1]{%
  \begingroup
    \renewcommand*{\arraystretch}{0.85}%
    \footnotesize\bfseries\begin{tabular}[b]{c}#1\end{tabular}%
  \endgroup
}

\setlength{\tabcolsep}{0pt}
\setlength{\extrarowheight}{2pt}
\begin{document}

\begin{table}[]
\caption{Access Latency, Energy, Power and Area Overheads of Precompression logic and Precompression-enabled caches.}
\label{table:precompression-overhead}

\centering
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
                                                l
                                                wr{1.2cm}
                                                wr{0.9cm}
                                                wr{1.45cm}
                                                wr{0.9cm}
                                                wr{1.55cm}
                                                wr{0.95cm}
                                                wr{1.4cm}
                                                wr{0.9cm}
                                                }
\toprule
\tstack{Cache Configuration} &
\tstack{Access\\ Latency\\ \scriptsize (ns)} &
\tstack{Over-\\head \\\scriptsize(\%)} &
\tstack{Dynamic\\Read\\ Energy\\ \scriptsize(nJ)} &
\tstack{Over-\\head\\\scriptsize(\%)} &
\tstack{Leakage \\Power\\ \scriptsize(mW)} &
\tstack{Over-\\head\\\scriptsize(\%)} &
\tstack{Area\\\scriptsize(mm\textsuperscript{2})} &
\tstack{Over-\\head\\\scriptsize(\%)} 
\\ \midrule
Conventional Cache (1MB)           & 1.3125 &      & 0.3295 &      & 221.796  &      & 3.4085  &      \\ 
Conventional Cache (8MB)           & 2.7504 &      & 0.8605 &      & 1641.110  &      & 18.7754 &      \\
Frequency Table (FT)               & 0.4129 &      & 0.0008 &      & 2.4785   &      & 0.0296  &      \\ Precompression Table (PT)          & 0.6353 &      & 0.0014 &      & 4.9366   &      & 0.0788  &      \\ 
Mapping Table (MT)                 & 0.0927 &      & 0.0011 &      & 0.3396   &      & 0.0032  &      \\ 
Overflow Mapping Table             & 0.3394 &      & 0.0020 &      & 4.5186   &      & 0.038   &      \\
Precompression-enabled Cache (1MB) & 2.2873 & 74  & 0.4178 & 26  & 273.539  & 23  & 3.9191  & 15  \\ 
Precompression-enabled Cache (8MB) & 3.7251 & 35  & 0.9489 & 10  & 1692.853 & 3   & 19.2859 & 5  \\ 
\bottomrule
\end{tabular*}
\end{table}

\end{document}

示例 2

在此处输入图片描述

\documentclass[UKenglish]{article}
\usepackage{array, tabulary, booktabs}
\usepackage{babel}
\usepackage{geometry}


\setlength{\tabcolsep}{4pt}
\setlength{\extrarowheight}{2pt}
\begin{document}

\begin{tabulary}{\textwidth}{|L|R|R|R|R|R|R|R|R|}
\hline
\textbf{Cache Configuration} &
  \textbf{Access Latency (ns)} &
  \textbf{Overhead (\%)} &
  \textbf{Dynamic Read Energy (nJ)} &
  \textbf{Overhead (\%)} &
  \textbf{Leakage Power (mW)} &
  \textbf{Overhead (\%)} &
  \textbf{Area (mm2)} &
  \textbf{Overhead} \\ \hline
Conventional Cache (1MB)           & 1.3125 &      & 0.3295 &      & 221.796  &      & 3.4085  &      \\ \hline
Conventional Cache (8MB)           & 2.7504 &      & 0.8605 &      & 1641.11  &      & 18.7754 &      \\ \hline
Frequency Table (FT)               & 0.4129 &      & 0.0008 &      & 2.4785   &      & 0.0296  &      \\ \hline
Precompression Table (PT)          & 0.6353 &      & 0.0014 &      & 4.9366   &      & 0.0788  &      \\ \hline
Mapping Table (MT)                 & 0.0927 &      & 0.0011 &      & 0.3396   &      & 0.0032  &      \\ \hline
Overflow Mapping Table             & 0.3394 &      & 0.0020 &      & 4.5186   &      & 0.038   &      \\ \hline
Precompression-enabled Cache (1MB) & 2.2873 & 74  & 0.4178 & 26  & 273.539  & 23  & 3.9191  & 15  \\ \hline
Precompression-enabled Cache (8MB) & 3.7251 & 35  & 0.9489 & 10  & 1692.853 & 3   & 19.2859 & 5  \\ \hline
\end{tabulary}
\caption{Access Latency, Energy, Power and Area Overheads of Precompression logic and Precompression-enabled caches.}
\label{table:precompression-overhead}
\end{table}

\end{document}

示例 3 - booktabs 和 tabulary

在此处输入图片描述

\documentclass[UKenglish]{article}
\usepackage{array, tabulary, booktabs}
\usepackage{babel}
\usepackage{geometry}


\setlength{\tabcolsep}{4pt}
\setlength{\extrarowheight}{2pt}
\begin{document}

\begin{table}[]
\centering\footnotesize

\begin{tabulary}{\textwidth}{@{}L*{8}{R}@{}}
\toprule
\textbf{Cache Configuration} &
  \centering\textbf{Access Latency (ns)} &
  \textbf{Overhead (\%)} &
  \centering\textbf{Dynamic Read Energy (nJ)} &
  \textbf{Overhead(\%)} &
  \centering\textbf{Leakage Power (mW)} &
  \textbf{Overhead (\%)} &
  \centering\textbf{Area (mm2)} &
  \textbf{Overhead (\%)} 
\\ \midrule
Conventional Cache (1MB)           & 1.3125 &      & 0.3295 &      & 221.796  &      & 3.4085  &      \\ 
Conventional Cache (8MB)           & 2.7504 &      & 0.8605 &      & 1641.110  &      & 18.7754 &      \\
Frequency Table (FT)               & 0.4129 &      & 0.0008 &      & 2.4785   &      & 0.0296  &      \\ Precompression Table (PT)          & 0.6353 &      & 0.0014 &      & 4.9366   &      & 0.0788  &      \\ \midrule
Mapping Table (MT)                 & 0.0927 &      & 0.0011 &      & 0.3396   &      & 0.0032  &      \\ 
Overflow Mapping Table             & 0.3394 &      & 0.0020 &      & 4.5186   &      & 0.038   &      \\
Precompression-enabled Cache (1MB) & 2.2873 & 74  & 0.4178 & 26  & 273.539  & 23  & 3.9191  & 15  \\ 
Precompression-enabled Cache (8MB) & 3.7251 & 35  & 0.9489 & 10  & 1692.853 & 3   & 19.2859 & 5  \\ 
\bottomrule
\end{tabulary}
\caption{Access Latency, Energy, Power and Area Overheads of Precompression logic and Precompression-enabled caches.}
\label{table:precompression-overhead}
\end{table}

\end{document}

答案4

我建议使用这个变体,使用基本tabular和可能性makecell

\documentclass[a4paper, fleqn, 10pt, oneside]{book}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{makecell}
\renewcommand\theadfont{\small\footnotesize}
\renewcommand\theadgape{}
\newrobustcmd{\myrothead}[1]{\rotatebox[origin=l]{30}{\rlap{#1}}\hfill\null}

\begin{document}

\begin{table}[!htb]
\centering
\small
\renewcommand{\theadfont}{\small}
\renewcommand{\cellset}{\renewcommand{\arraystretch}{0.6}}
\setcellgapes{3pt}
\makegapedcells
\settowidth\rotheadsize{\theadfont Dynamic Read}
\sisetup{table-text-alignment=left}
\begin{tabular}{!{\vline width 1pt} l|S[table-format=1.4, table-text-alignment=left]|c|
                                S[table-format=1.4]|c|
                                S[table-format=4.4]|c|
                                S[table-format=2.4]|c!{\vline width 1pt}}
\noalign{\vskip4ex}
\multicolumn{1}{l}{\raisebox{-1.5ex}{\thead[bl]{Cache\\ Configuration}}} &
  \multicolumn{1}{l}{\myrothead{\makecell[tl]{Access Latency\\[-1ex] (ns)}}}&
  \multicolumn{1}{l}{\myrothead{\raisebox{-1.5ex}{Overhead}}} &
  \multicolumn{1}{l}{\myrothead{\makecell[tl]{Dynamic Read\\[-1ex] Energy (nJ)}}} &
  \multicolumn{1}{l}{\myrothead{\raisebox{-1.5ex}{Overhead}}} &
  \multicolumn{1}{l}{\myrothead{\makecell[tl]{Leakage Power\\[-1ex] (mW)}}} &
 \multicolumn{1}{l}{\myrothead{\raisebox{-1.5ex}{Overhead}}} &
  \multicolumn{1}{l}{\myrothead{\raisebox{-1.5ex}{Area (mm2)}}} &
  \multicolumn{1}{l}{\myrothead{\raisebox{-1.5ex}{Overhead}}} \\ \Xhline{1pt}
\makecell[l]{Conventional \\Cache (1MB)} & 1.3125 & & 0.3295 & & 221.796 & & 3.4085 & \\ \hline
\makecell[l]{Conventional\\ Cache (8MB)} & 2.7504 & & 0.8605 & & 1641.11 & & 18.7754 & \\ \hline
\makecell[l]{Frequency Table\\ (FT)} & 0.4129 & & 0.0008 & & 2.4785 & & 0.0296 & \\ \hline
\makecell[l]{Precompression Table\\ (PT)} & 0.6353 & & 0.0014 & & 4.9366 & & 0.0788 & \\ \hline
\makecell[l]{Mapping Table\\ (MT)} & 0.0927 & & 0.0011 & & 0.3396 & & 0.0032 & \\ \hline
\makecell[l]{Overflow\\ Mapping Table} & 0.3394 & & 0.0020 & & 4.5186 & & 0.038 & \\ \hline
\makecell[l]{Precompression-enabled\\ Cache (1MB)} & 2.2873 & 74\% & 0.4178 & 26\% & 273.539 & 23\% & 3.9191 & 15\% \\ \hline
\makecell[l]{Precompression-enabled\\ Cache (8MB)} & 3.7251 & 35\% & 0.9489 & 10\% & 1692.853 & 3\% & 19.2859 & 5\% \\ \Xhline{1pt}
\end{tabular}
%
\caption{Access Latency, Energy, Power and Area Overheads of Precompression logic and Precompression-enabled caches.}
\label{table:precompression-overhead}
\end{table}

\end{document} 

在此处输入图片描述

相关内容