I'm new to LaTeX, and copied over a table from Excel into TeXShop (mac) using the macro. I set it as a longtable because it spans two pages, but with regard to width, the table isn't fitting.
Also, where can I insert the \label
and \caption
commands?
Here's the code I've used:
\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}
Best Answer
Concerning table size, you might put the unit and error on a second line, either by creating a second line of the table heading, like this:
or by using
\shortstack
, like this:The
\caption
and\label
can be used at the the begining (in this case, don't forget the\\
after\caption
) or at the end of the environmentlongtable
, as you normally do withtable
orfigure
. In other words,or
Hope it helps :)