表格看起来不太好 tabularx

表格看起来不太好 tabularx

我正在尝试用 Latex 制作表格,但我并不擅长,而且效果也不好。下面是我所做的,但结果不合适,看起来也不好,所以如果有人能告诉我如何正确格式化它:

\begin{table}
\centering\setlength{\tabcolsep}{.3\tabcolsep}
\begin{tabularx}{\linewidth}{|*2{>{\centering\hsize=1.6666\hsize}X|}*8{>{\centering\arraybackslash\hsize=.94444\hsize}X|}}
\hline
{\bf frfrfrfrf \textbackslash Point of Comparison} & {\bf Figure} & {\bf C-asasaseed} & {\bf A-asasaseed} & {\bf B-asasaseed} & {\bf Average asasaseed} & {\bf frfrfr} & {\bf Runtime}\\
\hline
hrhrheh (frwsrty sewcftyhd adrfraed) & Fig. 4a & 2.4216 & 2.2576 & 1.9949 & 2.2247 & $\mathcal{O}( n \times K * I * d )$ & 11 sec\\
\hline
fdfrfrf (hekko hdjek hsnejtls) & Fig. 4b &  2.4285 & 2.2496 & 1.9969 & 2.2250 & $\mathcal{O}( n * K * I * d )$ & 10 sec \\
\hline
bvgrfsf (nshehe sdf fdesf) & Fig. 4c & 2.4264 & 2.2520 & 1.9995 & 2.2260 & $\mathcal{O}( n * K * I * d )$ & 13 sec \\
\hline
asds A-ascsc & Fig. 4d & 2.1011 & 2.2388 & 1.9540 & 2.0980 & $\mathcal{O}(n * K * I)$ & 1 sec \\
\hline
      A-edede++ & Fig. 4e & 2.4570 & 2.2214 & 1.9937 & 2.2240 & $\mathcal{O}(\log{K})$ & 1 sec \\
\hline
    A-dedede & Fig. 4f & 2.3168 & 2.2255 & 1.9899 & 2.1774 & $\mathcal{O}(I * K * (n-K)^2)$ & 5 sec \\
\hline
asssse C-sdesd & Fig. 4g & 2.4033 & 2.2552 & 1.9991 & 2.2192 & $\mathcal{O}(n * d * K^2 * i)$ & 5 sec \\
\hline
 frfrf frfrfrfrfr frfrfrfrf & Fig. 4h & 2.4813 & 2.2187 & 1.9863 & 2.2288 & $\mathcal{O}(n * d * K^2 * i)$ & 312 sec\\
\hline
 dedededededed ededededededed sjsjsjsjsjs & Fig. 4i & 2.1853 & 1.9593 & 1.9593 & 2.0347 & $\mathcal{O}(n^2)$ & 7 sec \\
\hline
\end{tabularx}
\caption{jnflkrnflref rfref gregergedi  efreffe frefref frefref fr frfr frfrfrf frfrr frfr.}
\label{tab:template}
\end{table}

它看起来是这样的: 在此处输入图片描述

答案1

我建议您按如下方式进行:

  • 第二列的列类型也可以设置为c最小化其宽度

  • 对于其余七列,宽度比大约为 3:2 似乎比较合适。将\hsize最左侧列的设置为,将1.3其他六列的设置为0.95(注意:1.3 + 6*0.95 = 7)可能是一个不错的起点。您可以随意微调这些参数。

  • 使用\RaggedRightand \Centering(软件包提供的宏ragged2e)允许 LaTeX 对列内容进行连字符连接。\-在需要的地方添加显式自由选项 ( )。不出所料,LaTeX 不“知道”如何对较长的字符串(例如“edededededededed”)进行连字符连接。

  • 在第 2 列中,将所有 替换为 ,Fig.Fig.\告知 LaTeX 这些句号(“句号”)不是句末符号。节省更多空间...

  • \hline最后但同样重要的一点是,省略所有垂直规则,用包的规则绘制宏替换一些s booktabs,并用 替换所有其他水平线\addlinespace

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,booktabs,ragged2e}
\newcolumntype{Y}{>{\RaggedRight\hsize=1.35\hsize}X}
\newcolumntype{Z}{>{\Centering\hsize=.95\hsize\arraybackslash}X}
\begin{document}

\begin{table}
%\centering  %% not needed
\setlength{\tabcolsep}{.4\tabcolsep}
\begin{tabularx}{\linewidth}{@{} Y c *{7}{Z} @{}}
\toprule
\bfseries frfrfrfrf \textbackslash Point of Comparison & 
\bfseries Figure & 
\bfseries C-asasa\-seed & 
\bfseries A-asasa\-seed & 
\bfseries B-asasa\-seed & 
\bfseries Aver\-age asasa\-seed & 
\bfseries frfrfr & 
\bfseries Run\-time\\
\midrule
hrhrheh (frwsrty sewcftyhd adrfraed) & Fig.\ 4a & 2.4216 & 2.2576 & 1.9949 & 2.2247 & $\mathcal{O}( n \times K * I * d )$ & 11 sec\\
\addlinespace
fdfrfrf (hekko hdjek hsnejtls) & Fig.\ 4b &  2.4285 & 2.2496 & 1.9969 & 2.2250 & $\mathcal{O}( n * K * I * d )$ & 10 sec \\
\addlinespace
bvgrfsf (nshehe sdf fdesf) & Fig.\ 4c & 2.4264 & 2.2520 & 1.9995 & 2.2260 & $\mathcal{O}( n * K * I * d )$ & 13 sec \\
\addlinespace
asds A-ascsc & Fig.\ 4d & 2.1011 & 2.2388 & 1.9540 & 2.0980 & $\mathcal{O}(n * K * I)$ & 1 sec \\
\addlinespace
A-ede\-de++ & Fig.\ 4e & 2.4570 & 2.2214 & 1.9937 & 2.2240 & $\mathcal{O}(\log{K})$ & 1 sec \\
\addlinespace
    A-dedede & Fig.\ 4f & 2.3168 & 2.2255 & 1.9899 & 2.1774 & $\mathcal{O}(I * K * (n-K)^2)$ & 5 sec \\
\addlinespace
asssse C-sdesd & Fig.\ 4g & 2.4033 & 2.2552 & 1.9991 & 2.2192 & $\mathcal{O}(n * d * K^2 * i)$ & 5 sec \\
\addlinespace
 frfrf frfrfrfrfr frfrfrfrf & Fig.\ 4h & 2.4813 & 2.2187 & 1.9863 & 2.2288 & $\mathcal{O}(n * d * K^2 * i)$ & 312 sec\\
\addlinespace
 dededede\-deded ededede\-dededed sjsjsjsjsjs & Fig.\ 4i & 2.1853 & 1.9593 & 1.9593 & 2.0347 & $\mathcal{O}(n^2)$ & 7 sec \\
\bottomrule
\end{tabularx}
\caption{jnflkrnflref rfref gregergedi  efreffe frefref frefref fr frfr frfrfrf frfrr frfr.}
\label{tab:template}
\end{table}
\end{document}

答案2

再次尝试。如果没有文本,我真的不能确定我所做的布局调整是否有意义,但无论如何,还是要说一下:

\documentclass{article}
\usepackage{booktabs,siunitx,tabularx}

\begin{document}
\begin{table}
\small\setlength{\tabcolsep}{3.7pt}
\begin{tabularx}{\textwidth}%
  {>{\raggedright\arraybackslash}Xc*4{S[table-format=1.4]}>{$}c<{$}S[table-format=3.0]@{}}
\toprule
\hfill frfrfrfrf                         & & \multicolumn{4}{c}{asasaseed} & \text{frfrfr}  & {Runtime} \\
\cmidrule(lr){3-6}
Pt.~of Comparison                        & Fig. & {C} & {A} & {B} & {Avg.} & \mathcal{O}(\;)    & {(s)} \\
\midrule
hrhrheh (frwsrty sewcftyhd adrfraed)     & 4a   & 2.4216 & 2.2576 & 1.9949 & 2.2247 & n K I d     &  11 \\
fdfrfrf (hekko hdjek hsnejtls)           & 4b   & 2.4285 & 2.2496 & 1.9969 & 2.2250 & n K I d     &  10 \\
bvgrfsf (nshehe sdf fdesf)               & 4c   & 2.4264 & 2.2520 & 1.9995 & 2.2260 & n K I d     &  13 \\
asds A-ascsc                             & 4d   & 2.1011 & 2.2388 & 1.9540 & 2.0980 & n K I       &   1 \\
A-edede++                                & 4e   & 2.4570 & 2.2214 & 1.9937 & 2.2240 & \log{K}     &   1 \\
A-dedede                                 & 4f   & 2.3168 & 2.2255 & 1.9899 & 2.1774 & I K (n-K)^2 &   5 \\
asssse C-sdesd                           & 4g   & 2.4033 & 2.2552 & 1.9991 & 2.2192 & n d K^2 i   &   5 \\
frfrf frfrfrfrfr frfrfrfrf               & 4h   & 2.4813 & 2.2187 & 1.9863 & 2.2288 & n d K^2 i   & 312 \\
dedededededed ededededededed sjsjsjsjsjs & 4i   & 2.1853 & 1.9593 & 1.9593 & 2.0347 & n^2         &   7 \\
\bottomrule
\end{tabularx}
\caption{jnflkrnflref rfref gregergedi  efreffe frefref frefref fr frfr frfrfrf frfrr frfr.}
\label{tab:template}
\end{table}
\end{document}

在此处输入图片描述

答案3

怎么样?我抑制了所有垂直规则,加载了书本标签和单元格空间,以便在行之间实现更好的垂直间距。我还使用了siunitx数字对齐和makecell,这允许换行和列标题的通用格式。

%%%%%%%%%%
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{fourier}
\usepackage{ragged2e}
\usepackage{tabularx, booktabs}
\usepackage{siunitx}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}

\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{Y}{>{\RaggedRight\hsize=1.4\hsize}X}
\newcolumntype{Z}{>{\centering\arraybackslash\hsize=0.9\hsize}X}
\usepackage{cellspace}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\addparagraphcolumntypes{Y}
\begin{document}

\begin{table}
\small\centering\setlength\tabcolsep{5pt}
\begin{tabularx}{\linewidth}{C{Y}c*4{Z}@{}c@{}S[table-format = 2]}
\bottomrule
\thead{frfrfrfrf \textbackslash Point\\ of Comparison} & \thead{Figure} & \thead{C-\\asasaseed} & \thead{A-\\asasaseed} & \thead{B-\\asasaseed} & \thead{Average\\ asasaseed} & \thead{frfrfr} & {\thead{Runtime\\\mdseries(s)}} \\
\addlinespace[-1ex]
\midrule
hrhrheh (frwsrty sewcftyhd adrfraed) & Fig. 4a & 2.4216 & 2.2576 & 1.9949 & 2.2247 & $\mathcal{O}( n \times K * I * d )$ & 11 \\
fdfrfrf (hekko hdjek hsnejtls) & Fig. 4b & 2.4285 & 2.2496 & 1.9969 & 2.2250 & $\mathcal{O}( n * K * I * d )$ & 10 \\
bvgrfsf (nshehe sdf fdesf) & Fig. 4c & 2.4264 & 2.2520 & 1.9995 & 2.2260 & $\mathcal{O}( n * K * I * d )$ & 13 \\
asds A-ascsc & Fig. 4d & 2.1011 & 2.2388 & 1.9540 & 2.0980 & $\mathcal{O}(n * K * I)$ & 1 \\
  A-edede++ & Fig. 4e & 2.4570 & 2.2214 & 1.9937 & 2.2240 & $\mathcal{O}(\log{K})$ & 1 \\
A-dedede & Fig. 4f & 2.3168 & 2.2255 & 1.9899 & 2.1774 & $\mathcal{O}(I * K * (n-K)^2)$ & 5 \\
asssse C-sdesd & Fig. 4g & 2.4033 & 2.2552 & 1.9991 & 2.2192 & $\mathcal{O}(n * d * K^2 * i)$ & 5 \\
frfrf frfrfrfrfr frfrfrfrf & Fig. 4h & 2.4813 & 2.2187 & 1.9863 & 2.2288 & $\mathcal{O}(n * d * K^2 * i)$ & 312 \\
dedededededed ededededededed sjsjsjsjsjs & Fig. 4i & 2.1853 & 1.9593 & 1.9593 & 2.0347 & $\mathcal{O}(n^2)$ & 7 \\
\bottomrule
\end{tabularx}
\caption{jnflkrnflref rfref gregergedi efreffe frefref frefref fr frfr frfrfrf frfrr frfr.}
\label{tab:template}
\end{table}

\end{document} 

在此处输入图片描述

相关内容