我希望\hline
表格内部的长度与页面宽度相同。此外,我希望表格更细,就像示例图片(第二张)一样。我该怎么做?
\begin{table}[h]
\begin{center}
\begin{tabular}{rl}
\hline
methods &spearman correlation\\
PPMI + COSINE &0.25\\
PPMI + JACCARD& 0.58 \\
$\mathrm{PPMI}_{\alpha}+$ COSINE & 0.00 \\
$\mathrm{PPMI}_{\alpha}+$ JACCARD& -0.03 \\
\hline
\end{tabular}
\caption{This table shows the Spearman's rank for four methods}
\label{tab:sample-table}
\end{center}
\end{table}
答案1
一个非常简单的方法是使用\hrulefill
。我对表格进行了改进siunitx
,以便右列中的数字在小数点上对齐:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{table}[h]
\centering
\hrulefill\par
\begin{tabular}{rS[table-format=-1.2, table-number-alignment=left]}
methods &\multicolumn{1}{l}{ spearman correlation} \\
PPMI + COSINE &0.25 \\
PPMI + JACCARD& 0.58 \\
$\mathrm{PPMI}_{\alpha}+$ COSINE & 0.00 \\
$\mathrm{PPMI}_{\alpha}+$ JACCARD& -0.03 \\
\end{tabular}\par
\hrulefill
\caption{This table shows the Spearman's rank for four methods}
\label{tab:sample-table}
\end{table}
\end{document}
答案2
如果您所说的“pagewidth”是指页面上文本的宽度,即,\textwidth
那么以下建议可能会有用:
\documentclass{article}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage[skip=1ex]{caption}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\begin{document}
\begin{table}[ht]
\setlength\arrayrulewidth{.15pt}
\begin{tabularx}{\linewidth}{XrS[table-format=-1.2,table-number-alignment=left]X}
\hline
& methods &\multicolumn{1}{l}{spearman correlation}& \\
& PPMI + COSINE & 0.25 & \\
& PPMI + JACCARD & 0.58 & \\
& PPMI\textsubscript{$\alpha$} + COSINE & 0.00 & \\
& PPMI\textsubscript{$\alpha$} + JACCARD & -0.03 & \\
\hline
\end{tabularx}
\caption{This table shows the Spearman's rank for four methods}
\label{tab:sample-table}
\end{table}
\end{document}
(红线表示页面布局)
答案3
可以吗?我猜你指的是 textwidth 而不是 pagewidth。
\documentclass[12pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage[utf8]{vietnam}
\usepackage{tikz}
%\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[yscale=.5]
\pgfmathsetmacro{\a}{\textwidth}
\draw (0,0)--+(0:\a pt) (0,-6)--+(0:\a pt);
\path[left=5mm]
(\a/2 pt,-1) node{methods}
++(-90:1) node{PPMI + COSINE}
++(-90:1) node{PPMI + JACCARD}
++(-90:1) node{${\rm PPMI}_{\alpha}$ + COSINE}
++(-90:1) node{${\rm PPMI}_{\alpha}$ + JACCARD};
\path[right=5mm]
(\a/2 pt,-1) node{spearman correlation}
++(-90:1) node{0.25}
++(-90:1) node{0.58}
++(-90:1) node{0.00}
++(-90:1) node{-0.33};
\end{tikzpicture}
\end{document}
编辑:我改为pt
使cm
代码更简洁,并使用 lipsum 包来说明textwidth
表格。
\documentclass[12pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{tikz}
\usepackage{lipsum}
%\usepackage{siunitx}
\begin{document}
\lipsum[1-1]
\vspace*{2mm}
\noindent
\begin{tikzpicture}[yscale=.5]
\pgfmathsetmacro{\a}{\textwidth*0.0352778} % pt to cm
\draw (0,0)--+(0:\a) (0,-6)--+(0:\a);
\path[left=5mm]
(\a/2,-1) node{methods}
++(-90:1) node{PPMI + COSINE}
++(-90:1) node{PPMI + JACCARD}
++(-90:1) node{${\rm PPMI}_{\alpha}$ + COSINE}
++(-90:1) node{${\rm PPMI}_{\alpha}$ + JACCARD};
\path[right=5mm]
(\a/2,-1) node{spearman correlation}
++(-90:1) node{0.25}
++(-90:1) node{0.58}
++(-90:1) node{0.00}
++(-90:1) node{-0.33};
\end{tikzpicture}
\vspace*{2mm}
\lipsum[1-1]
\end{document}