![如何让宽长的表格适合页面?](https://linux22.com/image/281263/%E5%A6%82%E4%BD%95%E8%AE%A9%E5%AE%BD%E9%95%BF%E7%9A%84%E8%A1%A8%E6%A0%BC%E9%80%82%E5%90%88%E9%A1%B5%E9%9D%A2%EF%BC%9F.png)
我是 LaTeX 新手,使用宏将 Excel 中的表格复制到 TeXShop (mac) 中。我将其设置为 longtable,因为它跨越两页,但就宽度而言,表格不合适。另外,我可以在哪里插入和\label
命令\caption
?
以下是我使用的代码:
\documentclass[12pt,a4paper]{report}
\title{}
\author{}
\date{}
%This introduces packages that will be used in the text
\usepackage{longtable}
\usepackage{graphicx}
\usepackage{url}
\usepackage{float}
\usepackage{siunitx}
% lscape.sty Produce landscape pages in a (mainly) portrait document.
\usepackage{lscape}
%This sets new commands/shortcuts that can be used
\newcommand{\ecoli}{\emph{Escherichia coli }}
\newcommand{\PCMX}{Chloroxylenol }
\newcommand{\potperm}{Potassium Permanganate}
\newcommand{\mhagar}{Mueller-Hinton Agar}
\newcommand{\sulfuricacid}{H$_2$SO$_4$}
\begin{landscape}
\subsection{Blank Data Tables}
%Table generated by macro in TeXShop by copy-pasting table from Excel
\begin{longtable}{lllllllll}
No. & Juice & Loc. & Samp.No. & Dettol /mm$\pm$0.05 & Ethanol /mm$\pm$0.05 & 2M \sulfuricacid /mm$\pm$0.05 & H$^+$/KMnO$_4$ /mm$\pm$0.05 & Control/mm$\pm$0.05 \\
\endfirsthead
No. & Juice & Loc. & Samp.No. & Dettol /mm$\pm$0.05 & Ethanol /mm$\pm$0.05 & 2M \sulfuricacid /mm$\pm$0.05 & H$^+$/KMnO$_4$ /mm$\pm$0.05 & Control/mm$\pm$0.05 \\
\endhead
\multicolumn{9}{r}{{Continued\ldots}} \
\endfoot
\hline
\endlastfoot
1 & Sugarcane & 1 & 1 \\
2 & Sugarcane & 1 & 2 \\
3 & Sugarcane & 1 & 3 \\
4 & Sugarcane & 1 & 4 \\
5 & Sugarcane & 1 & 5 \\
6 & Orange & 1 & 1 \\
7 & Orange & 1 & 2 \\
8 & Orange & 1 & 3 \\
9 & Orange & 1 & 4 \\
10 & Orange & 1 & 5 \\
11 & Carrot & 1 & 1 \\
12 & Carrot & 1 & 2 \\
13 & Carrot & 1 & 3 \\
14 & Carrot & 1 & 4 \\
15 & Carrot & 1 & 5 \\
16 & Sugarcane & 2 & 1 \\
17 & Sugarcane & 2 & 2 \\
18 & Sugarcane & 2 & 3 \\
19 & Sugarcane & 2 & 4 \\
20 & Sugarcane & 2 & 5 \\
21 & Orange & 2 & 1 \\
22 & Orange & 2 & 2 \\
23 & Orange & 2 & 3 \\
24 & Orange & 2 & 4 \\
25 & Orange & 2 & 5 \\
26 & Carrot & 2 & 1 \\
27 & Carrot & 2 & 2 \\
28 & Carrot & 2 & 3 \\
29 & Carrot & 2 & 4 \\
30 & Carrot & 2 & 5 \\
31 & Sugarcane & 3 & 1 \\
32 & Sugarcane & 3 & 2 \\
33 & Sugarcane & 3 & 3 \\
34 & Sugarcane & 3 & 4 \\
35 & Sugarcane & 3 & 5 \\
36 & Orange & 3 & 1 \\
37 & Orange & 3 & 2 \\
38 & Orange & 3 & 3 \\
39 & Orange & 3 & 4 \\
40 & Orange & 3 & 5 \\
41 & Carrot & 3 & 1 \\
42 & Carrot & 3 & 2 \\
43 & Carrot & 3 & 3 \\
44 & Carrot & 3 & 4 \\
45 & Carrot & 3 & 5 \\
\end{longtable}
\end{landscape}
\end{document}
答案1
关于表格大小,您可以将单位和错误放在第二行,方法是创建表格标题的第二行,如下所示:
No. & Juice & Loc. & Samp.No. & Dettol & Ethanol & 2M \sulfuricacid & H$^+$/KMnO$_4$ & Control \\
& & & & mm$\pm0.05$ & mm$\pm$0.05 & mm$\pm$0.05 & mm$\pm$0.05 & mm$\pm$0.05\\
或者使用\shortstack
,如下所示:
No. & Juice & Loc. & Samp.No. & \shortstack{Dettol\\mm$\pm$0.05} & \shortstack{Ethanol\\mm$\pm$0.05} & \shortstack{2M \sulfuricacid\\mm$\pm$0.05} & \shortstack{H$^+$/KMnO$_4$\\mm$\pm$0.05} & \shortstack{Control\\mm$\pm$0.05} \\
and可以放在环境\caption
的\label
开头(在这种情况下,不要忘记\\
后面的\caption
)或结尾longtable
,就像通常使用table
or一样figure
。换句话说,
\begin{longtable}{lllllllll}
\caption{...}\label{...}\\
...
或者
...
\caption{...}\label{...}
\end{longtable}
希望能帮助到你 :)
答案2
/mm$\pm0.05$
如果我理解您的设置正确的话,您有五列,其单位以(并且您可能会使用包S
的列类型)来衡量siunitx
。您可以将有关常用单位的信息移动到第二行,通过跨越数据列的 将此信息绑定到五个数据列\cmidrule
。
下图仅显示表格的标题和前几行,为了使其更易于阅读,故意没有旋转 90 度转换为横向格式。
\documentclass[12pt,a4paper]{report}
\usepackage{longtable,lscape,siunitx} % load just the packages needed for this MWE
%This sets new commands/shortcuts that can be used
\newcommand{\ecoli}{\emph{Escherichia coli }}
\newcommand{\PCMX}{Chloroxylenol }
\newcommand{\potperm}{Potassium Permanganate}
\newcommand{\mhagar}{Mueller-Hinton Agar}
\newcommand{\sulfuricacid}{H$_2$SO$_4$}
\usepackage{booktabs} % for \toprule, \midrule, \cmidrule, and \bottomrule macros
\begin{document}
\begin{landscape}
\subsection{Blank Data Tables}
%Table generated by macro in TeXShop by copy-pasting table from Excel
\begin{longtable}{llll *{5}{S[table-format=3.2]}} % set 'table-format' to suit your needs
\toprule
No. & Juice & Loc. & Samp.~No. &
{Dettol} & {Ethanol} & {2M \sulfuricacid} & {H$^+$/KMnO$_4$} & {Control} \\
\cmidrule(l){5-9}
&&&& \multicolumn{5}{c}{[ /mm $\pm 0.05$ ]}\\
\midrule
\endhead
\midrule[\heavyrulewidth]
\multicolumn{9}{r@{}}{Continued \ldots} \\
\endfoot
\bottomrule
\endlastfoot
1 & Sugarcane & 1 & 1 \\
2 & Sugarcane & 1 & 2 \\
3 & Sugarcane & 1 & 3 \\
4 & Sugarcane & 1 & 4 \\
5 & Sugarcane & 1 & 5 \\
6 & Orange & 1 & 1 \\
7 & Orange & 1 & 2 \\
8 & Orange & 1 & 3 \\
9 & Orange & 1 & 4 \\
10 & Orange & 1 & 5 \\
11 & Carrot & 1 & 1 \\
12 & Carrot & 1 & 2 \\
13 & Carrot & 1 & 3 \\
14 & Carrot & 1 & 4 \\
15 & Carrot & 1 & 5 \\
16 & Sugarcane & 2 & 1 \\
17 & Sugarcane & 2 & 2 \\
18 & Sugarcane & 2 & 3 \\
19 & Sugarcane & 2 & 4 \\
20 & Sugarcane & 2 & 5 \\
21 & Orange & 2 & 1 \\
22 & Orange & 2 & 2 \\
23 & Orange & 2 & 3 \\
24 & Orange & 2 & 4 \\
25 & Orange & 2 & 5 \\
26 & Carrot & 2 & 1 \\
27 & Carrot & 2 & 2 \\
28 & Carrot & 2 & 3 \\
29 & Carrot & 2 & 4 \\
30 & Carrot & 2 & 5 \\
31 & Sugarcane & 3 & 1 \\
32 & Sugarcane & 3 & 2 \\
33 & Sugarcane & 3 & 3 \\
34 & Sugarcane & 3 & 4 \\
35 & Sugarcane & 3 & 5 \\
36 & Orange & 3 & 1 \\
37 & Orange & 3 & 2 \\
38 & Orange & 3 & 3 \\
39 & Orange & 3 & 4 \\
40 & Orange & 3 & 5 \\
41 & Carrot & 3 & 1 \\
42 & Carrot & 3 & 2 \\
43 & Carrot & 3 & 3 \\
44 & Carrot & 3 & 4 \\
45 & Carrot & 3 & 5 \\
\end{longtable}
\end{landscape}
\end{document}