我在 LaTeX 中制作了一个表格。表格图像如下所示:
该表的代码如下:
\begin{table}[!ht]
\begin{center}
\caption{Actors vs Positional Dynamicity (based on Closeness Centrality) in Different LSNs} \label{pos1}
\begin{tabular}{|c||c| c| c| c| c|}
\hline
Actor\\ No. & LSN 1 & LSN 2 & LSN 3 & ... & LSN 60 \\ [0.5ex]
\hline\hline
1 &0.205602 &0.262515 & 0.247979 &... & 0.170467 \\
\hline
2 &0.00961852 &0.0200901 & 0.0207746 &... & 0.107013 \\
\hline
3 &0.1271 & 0.170967 & 0.199928 &... &0.173208 \\
\hline
4 & 0.00263733 & 0.00524802 & 0.00787202 &... &0.0100803 \\
\hline
5 & 0.00300429 &0.00597824 & 0.00673418 &... & 0.00706005 \\
\hline
... & ... & ... & ... &... . &... \\
\hline
1899 &0.00994494 &0.00968842 & 0.0216411 &...&0.0610909 \\
\hline
\end{tabular}
\end{center}
\end{table}
有什么方法可以正确适应列分隔符的宽度(在图中用红色标记)?
答案1
您可以使用makecell
,它允许在单元格中换行,并hhline
具有更美观的交叉双线,或者在表格中使用一些颜色。以下是两种解决方案:
\documentclass{article}
\usepackage{hhline}
\usepackage{makecell, caption, booktabs}
\usepackage{siunitx}
\usepackage[table, svgnames]{xcolor}
\colorlet{tbgcolour}{Gainsboro!70!Lavender!50! white}
\captionsetup{font=small}
\begin{document}
\begin{table}[!htb]
\centering\sisetup{table-format=1.8, table-number-alignment=center}
\setlength{\extrarowheight}{2.5pt}
\caption{Actors vs Positional Dynamicity (based on Closeness Centrality) in Different LSNs} \label{pos1}
\begin{tabular}{|c||*{3}{S|} c|S|}
\hhline{-||-----|}
\makecell{Actor\\ No. } & {LSN 1} & {LSN 2} & {LSN 3} & ... & {LSN 60} \\ [0.5ex]
\hhline{=::=====}
1 &0.205602 &0.262515 & 0.247979 &... & 0.170467 \\
\hhline{-||-----|}
2 &0.00961852 &0.0200901 & 0.0207746 &... & 0.107013 \\
\hhline{-||-----|}
3 &0.1271 & 0.170967 & 0.199928 &... &0.173208 \\
\hhline{-||-----|}
4 & 0.00263733 & 0.00524802 & 0.00787202 &... &0.0100803 \\
\hhline{-||-----|}
5 & 0.00300429 &0.00597824 & 0.00673418 &... & 0.00706005 \\
\hhline{-||-----|}
... & ... & ... & ... &... . &... \\
\hhline{-||-----|}
1899 &0.00994494 &0.00968842 & 0.0216411 &...&0.0610909 \\
\hhline{-||-----|}
\end{tabular}
\end{table}
\begin{table}[!htb]
\centering\sisetup{table-format=1.8, table-number-alignment=center}
\caption{Actors vs Positional Dynamicity (based on Closeness Centrality) in Different LSNs} \label{pos1}
\arrayrulecolor{DarkOrange!50}
\setlength{\arrayrulewidth}{0.6pt}
\setlength{\extrarowheight}{2.5pt}
\begin{tabular}{>{\columncolor{tbgcolour}[\tabcolsep][\tabcolsep]}c!{\hspace{0.5ex}}*{3}{|S}|c|S|}%
\rowcolor{tbgcolour} \multicolumn{1}{c!{\color{white}\vrule width 4.4pt}}{\makecell{Actor\\ No.}} & \multicolumn{1}{!{\color{tbgcolour}\vrule\hspace{-2\arrayrulewidth}}c}{LSN 1} & \multicolumn{1}{c}{LSN 2} & \multicolumn{1}{c}{LSN 3} & \multicolumn{1}{c}{...} & \multicolumn{1}{c}{LSN 60} \\
\addlinespace[1ex]
\cline{2-6}
1 & 0.205602 &0.262515 & 0.247979 &... & 0.170467 \\
\cline{2-6}
2 & 0.00961852 &0.0200901 & 0.0207746 &... & 0.107013 \\
\cline{2-6}
3 & 0.1271 & 0.170967 & 0.199928 &... &0.173208 \\
\cline{2-6}
4 & 0.00263733 & 0.00524802 & 0.00787202 &... &0.0100803 \\
\cline{2-6}
5 & 0.00300429 &0.00597824 & 0.00673418 &... & 0.00706005 \\
\cline{2-6}
... & ... & ... & ... &... . &... \\
\cline{2-6}
1899 & 0.00994494 &0.00968842 & 0.0216411 &...&0.0610909 \\
\cline{2-6}
\end{tabular}
\end{table}
\end{document}
答案2
.tex
在询问此类问题时,请务必提供完整(但最小)的文件。
以下有两种方法:
\documentclass{article}
\begin{document}
\begin{table}[!ht]
\begin{center}
\begin{tabular}{|c||c| c| c| c| c|}
\hline
Actor &&&&&\\
No. & LSN 1 & LSN 2 & LSN 3 & ... & LSN 60 \\
\hline\hline
\shortstack{Actor\\ No.} & LSN 1 & LSN 2 & LSN 3 & ... & LSN 60
\\ [0.5ex]
\hline\hline
1 &0.205602 &0.262515 & 0.247979 &... & 0.170467 \\
\hline
2 &0.00961852 &0.0200901 & 0.0207746 &... & 0.107013 \\
\hline
3 &0.1271 & 0.170967 & 0.199928 &... &0.173208 \\
\hline
4 & 0.00263733 & 0.00524802 & 0.00787202 &... &0.0100803 \\
\hline
5 & 0.00300429 &0.00597824 & 0.00673418 &... & 0.00706005 \\
\hline
... & ... & ... & ... &... . &... \\
\hline
1899 &0.00994494 &0.00968842 & 0.0216411 &...&0.0610909 \\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
就我个人而言,我会避免使用这种风格的表格,而使用类似于回答你的其他几乎相同的问题。