0

I want my \hline inside the table as long as the page width. In addition, I want to make it thinner, just like the example picture (the second one). How can I do this?

\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}

short hline This is the current short hline table.

Expectation This is my expectation.

Alan Munn
  • 218,180
NNNBN
  • 1
  • Welcome to TeX.SE! From your second image can be concluded, that \hline start at left text border and end on the right page border. Do I'm right? A way to accomplish your wish is change for this table a text width for example with use of the changepage package. Thickness of \hline you can change with \setlength\arrayrulewidth{<desired width>} . BTW, used fonts in your table is not consistent. – Zarko Jul 28 '19 at 22:24
  • 1
    For future questions, please don't post code fragments. Instead put the fragment into a complete compilable document that people can play with. – Alan Munn Jul 28 '19 at 22:36

3 Answers3

7

A very simple way to do that with \hrulefill. I added an improvement to the table with siunitx, so the numbers in the right column be aligned on the decimal dot:

\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} 

enter image description here

Bernard
  • 271,350
3

If you mean with "pagewidth" the width of text on page, i.e.; \textwidth, than the following suggestion can be useful:

\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}

enter image description here

(red lines indicate page layout)

Zarko
  • 296,517
1

Is it okay? I guess you mean textwidth instead of pagewidth.

enter image description here

\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}

Edit: I change pt to cm to make code cleaner, and use lipsum package to illustrating textwidth of the table.

enter image description here

\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}
Black Mild
  • 17,569