1

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

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:

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

or by using \shortstack, like this:

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

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 environment longtable, as you normally do with table or figure. In other words,

\begin{longtable}{lllllllll}
\caption{...}\label{...}\\
...

or

...
\caption{...}\label{...}
\end{longtable}

Hope it helps :)

1

If I understand your setup correctly, you have five columns whose units are measured in /mm$\pm0.05$ (and for which you will probably use the S column type of the siunitx package). You could move the information about the common units to a second row, tying this informaton to the five data columns via a \cmidrule that spans the data columns.

The following image, which shows just the table's header and first few rows, is deliberately not turn 90 degrees to landscape format in order to make it more easily readable.

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.