我想使用\longtable
包创建一个表。我尝试了以下方法:
\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float,lipsum,subfig,booktabs}
\usepackage{mathtools,array,dcolumn,longtable}
\begin{document}
\begin{longtable}{|*4{p{2cm}|}}
\toprule
low threshold (\%)& L mean& R mean observed & R mean predicted\\
\hline
85 &188.2 &10.0 &\textbf{8.6} \\
80 &375.3 &10.5 &\textbf{20} \\
75 &326.2 &23.4 &\textbf{19.1} \\
40 &247.1 &15.6 &\textbf{14.3} \\
30 &215.1 &18.2 &\textbf{11.5} \\
25 &258.9 &16.0 &\textbf{15.2} \\
20 &243.8 &16.9 &\textbf{14.1} \\
20 &264.0 &11.8 &\textbf{15.6} \\
10 &285.4 &17.6 &\textbf{16.5} \\
10 &295.7 &19.3 &\textbf{17.1} \\
5 &239.9 &14.7 &\textbf{13.9}\\
5 &281.3 &23.3 &\textbf{16.3}\\
0 &780.0 &49.1 &\textbf{50.6}\\
0 &264 &11.8 &\textbf{15.6}\\
0 &285.8 &17.6 &\textbf{16.5}\\
0 &295.7 &19.3 &\textbf{17.1}\\
0 &239.9 &14.7 &\textbf{13.9}\\
0 &296.9 &18.4 &\textbf{17.4}\\
0 &304.8 &21.1 &\textbf{18.0}\\
0 &321.9 &21.6 &\textbf{19.1}\\
0 &375.6 &27.1 &\textbf{20.3}\\
0 &413.0 &21.1 &\textbf{21.4}\\
0 &444.9 &18.4 &\textbf{22.8}\\
0 &449.1 &34.3 &\textbf{23.3}\\
0 &484.7 &34.3 &\textbf{25.3}\\
0 &489.3 &33.9 &\textbf{25.3}\\
0 &505.8 &21.1 &\textbf{26.4}\\
0 &542.1 &41.9 &\textbf{28.3}\\
0 &563.9 &34.3 &\textbf{29.8}\\
0 &572.4 &34.3 &\textbf{30.3}\\
0 &646.2 &34.3 &\textbf{35.7}\\
0 &662.2 &41.9 &\textbf{36.9}\\
0 &538.8 &23.1 &\textbf{28.7}\\
0 &466.3 &18.2 &\textbf{24.2}\\
0 &377.9 &12.7 &\textbf{20.4}\\
0 &636.7 &32.6 &\textbf{35.2}\\
0 &691.2 &38.4 &\textbf{38.6}\\
0 &766.8 &48.6 &\textbf{43.3}\\
0 &614.5 &24.3 &\textbf{33.6}\\
0 &543.7 &23.0 &\textbf{29.0}\\
0 &499.8 &16.5 &\textbf{25.9}\\
0 &710.3 &35.1 &\textbf{38.8}\\
0 &774.0 &50.5 &\textbf{48.5}\\
0 &780.0 &49.1 &\textbf{50.6}\\
0 &761.3 &49.5 &\textbf{41.1}\\
0 &762.9 &50.1 &\textbf{41.4}\\
0 &767.0 &50.3 &\textbf{43.4}\\
0 &588.1 &35.0 &\textbf{31.4}\\
0 &601.7 &38.7 &\textbf{32.6}\\
0 &423.9 &11.3 &\textbf{21.9}\\
0 &425.3 &10.5 &\textbf{22.2}\\
0 &623.7 &29.9 &\textbf{33.7}\\
\bottomrule
\caption{}
\end{longtable}
\end{document}
我想将表格的宽度设置为文本宽度,同时还想使其布局不那么难看 :D 目前原始元素之间的空间太大。有什么建议吗?
答案1
设计表格的一种可能性是:
\documentclass[11pt]{report}
\usepackage[nodisplayskipstretch]{setspace}
\onehalfspacing
\usepackage{geometry}
\usepackage[skip=1ex]{caption}
\usepackage{booktabs,longtable}
\usepackage{siunitx} % <-- new
\usepackage{etoolbox}% <-- new
\newrobustcmd{\B}{\bfseries}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\singlespacing % <---
\begin{longtable}{S[table-format=2.0]
*{2}{S[table-format=2.1]}
S[table-format=2.1,detect-weight]
}
\caption{Caption should be here}
\label{tab:mylongtable} \\
\toprule
{low threshold (\%)}
& {L mean }& {R mean observed} & {R mean predicted} \\
\midrule
\endfirsthead
\caption[]{Caption should be here (cont.)} \\
\toprule
{low threshold (\%)}
& {L mean }& {R mean observed} & {R mean predicted} \\
\midrule
\endhead
\midrule[\heavyrulewidth]
\multicolumn{4}{r}{\footnotesize\textit{Contionued on the next page}}
\endfoot
\bottomrule
\endlastfoot
85 &188.2 &10.0 &\B 8.6 \\
80 &375.3 &10.5 &20 \\
75 &326.2 &23.4 &19.1 \\
40 &247.1 &15.6 &14.3 \\
30 &215.1 &18.2 &11.5 \\
25 &258.9 &16.0 &15.2 \\
20 &243.8 &16.9 &14.1 \\
20 &264.0 &11.8 &15.6 \\
10 &285.4 &17.6 &16.5 \\
10 &295.7 &19.3 &17.1 \\
5 &239.9 &14.7 &13.9 \\
5 &281.3 &23.3 &16.3 \\
0 &780.0 &49.1 &\B 50.6 \\
0 &264 &11.8 &15.6 \\
0 &285.8 &17.6 &16.5 \\
0 &295.7 &19.3 &17.1 \\
0 &239.9 &14.7 &13.9 \\
0 &296.9 &18.4 &17.4 \\
0 &304.8 &21.1 &18.0 \\
0 &321.9 &21.6 &19.1 \\
0 &375.6 &27.1 &20.3 \\
0 &413.0 &21.1 &21.4 \\
0 &444.9 &18.4 &22.8 \\
0 &449.1 &34.3 &23.3 \\
0 &484.7 &34.3 &25.3 \\
0 &489.3 &33.9 &25.3 \\
0 &505.8 &21.1 &26.4 \\
0 &542.1 &41.9 &28.3 \\
0 &563.9 &34.3 &29.8 \\
0 &572.4 &34.3 &30.3 \\
0 &646.2 &34.3 &35.7 \\
0 &662.2 &41.9 &36.9 \\
0 &538.8 &23.1 &28.7 \\
0 &466.3 &18.2 &24.2 \\
0 &377.9 &12.7 &20.4 \\
0 &636.7 &32.6 &35.2 \\
0 &691.2 &38.4 &38.6 \\
0 &766.8 &48.6 &43.3 \\
0 &614.5 &24.3 &33.6 \\
0 &543.7 &23.0 &29.0 \\
0 &499.8 &16.5 &25.9 \\
0 &710.3 &35.1 &38.8 \\
0 &774.0 &50.5 &48.5 \\
0 &780.0 &49.1 &50.6 \\
0 &761.3 &49.5 &41.1 \\
0 &762.9 &50.1 &41.4 \\
0 &767.0 &50.3 &43.4 \\
0 &588.1 &35.0 &31.4 \\
0 &601.7 &38.7 &32.6 \\
0 &423.9 &11.3 &21.9 \\
0 &425.3 &10.5 &22.2 \\
0 &623.7 &29.9 &33.7 \\
\end{longtable}
\onehalfspacing % <---
\lipsum[2]
\end{document}
生成下表:
(红线表示页面布局)