# Long table doesn't fit in page

I'be been using the longtable environment to construct the outlined below (This is only part of the data. The whole data runs over 4 pages and is much wider). The problem that I'm having is that the data runs over the right margin and I get the following error:

Overfull \hbox (605.54675pt too wide) in alignment at lines 12--40.

I've been told that there is no command which automatically adjust the table to fit in the page. However, I would like to know if

1. there is a way to decrease the distance between each column and
2. Make the font size smaller in the table so that all the columns fit in the page.

I've read the other posts that are similar to this question however I'm new to LaTeX and I'm having a hard time finding a solution to this problem. Can anyone help? Thanks Alex

\documentclass{article}
\usepackage{longtable}
\usepackage{ltablex}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,}
\begin{document}

\begin{longtable}{lllllll}

\toprule[1pt]
& \multicolumn{4}{r}{Spectral Index} \\
\cmidrule(l{1pt}){4-5}
\emph{MGI Symbols} & \emph{Protein Name} & \emph{UniProt Acc} & \emph{AveKI} & \emph{AveWT} & \emph{KI/WT Ratio} & \emph{Cluster}\vspace{5mm} \\\midrule

Title/Title\vspace{5mm}\\

$Amph$ & Amphiphysin & Q7TQF7 & 1.42E-06 & 0.00E+00 & KI Only & X6\\
$Bin1$ & Myc Box-Dependent-Interacting Protein 1 & O08539 & 1.20E-06 & 0.00E+00 & KI Only & X6\\
$Cltc$ & Clathrin Heavy Chain 1 & Q68FD5 & 5.88E-07 & 6.00E-08 & 9.80 & X6\\
$Dnm1$ & Dynamin-1 & P39053 & 1.97E-06 & 3.41E-08 & 57.76 & X6\\
$Nsf$ & Vesicle Fusing ATPase & P46460 & 3.43E-07 & 0.00E+00 & KI Only & X6\\
$Snap25$ & Synaptosomal-Associated Protein 25 & P60879 & 8.90E-06 & 3.27E-06 & 2.72 & B\\
$Stxbp1$ & Isoform 2 Of Syntaxin-Binding Protein 1 & O08599 & 1.22E-06 & 0.00E+00 & KI Only & X6\\
$Syt1$ & Synaptotagmin 1 & P21579 & 1.02E-05 & 4.81E-06 & 2.13 & B\vspace{5mm}\\

\vspace{5mm}\\\bottomrule
\hline

\end{longtable}

\end{document}
• Welcome, you cannot fit an elephant in a suitcase. You have different options: Shrink the elephant (smaller font size), enlarge the suitcase (larger page), cut the elephant in parts (split to different pages), just include a part of the elephant (avoid redundant or unneded data) or put a phot of an elephant in the suitcase (plot data in a diagram). – Johannes_B Aug 1 '16 at 11:53
• You didn't get this error with your code. It perfectly fits the margins. – Bernard Aug 1 '16 at 12:14
• Your table -- as far as you shown -- is narrowed than text width. But you have errors in the first table row: & \multicolumn{4}{r}{Spectral Index} \\ \cmidrule(l{1pt}){4-5}. In it are missed two columns. For further help you need to extend table contents for a list few more rows. Maybe is there content, which is wider than text. – Zarko Aug 1 '16 at 12:34
• Do you know by any chance the command to adjust the table automatically to the margins even if it makes the font smaller like the adjust box command in tabular? – user110968 Aug 1 '16 at 13:32
• @user110968 - There is no such command for longtables. – Mico Aug 1 '16 at 13:55

One problem in your table is, that the protein names are very long. If you break their names over multiple lines, you automatically get more space. Same with the long headline of the "MGI Symbols".

I am not sure, why you put the symbol names into a math environment, but if you want them in italic, please don't use math!

[As your code is unclear to me, please check, if my interpretation of the headline is correct]

\documentclass{article}
\usepackage{longtable}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}

\begin{document}

\begin{longtable}{lp{4.7cm}lllll}
\toprule
\emph{MGI} & & & \multicolumn{2}{c}{Spectral Index} & & \\
\cmidrule(l{1pt}){4-5}
\emph{Symbols} & \emph{Protein Name} & \emph{UniProt Acc} & \emph{AveKI} & \emph{AveWT} & \emph{KI/WT Ratio} & \emph{Cluster}\\
\midrule
\textit{Amph} & Amphiphysin & Q7TQF7 & 1.42E-06 & 0.00E+00 & KI Only & X6\\
\textit{Bin1} & Myc Box-Dependent-\newline Interacting Protein 1 & O08539 & 1.20E-06 & 0.00E+00 & KI Only & X6\\
\textit{Cltc} & Clathrin Heavy Chain 1 & Q68FD5 & 5.88E-07 & 6.00E-08 & 9.80 & X6\\
\textit{Dnm1} & Dynamin-1 & P39053 & 1.97E-06 & 3.41E-08 & 57.76 & X6\\
\textit{Nsf} & Vesicle Fusing ATPase & P46460 & 3.43E-07 & 0.00E+00 & KI Only & X6\\
\textit{Snap25} & Synaptosomal-As\-so\-ci\-ated Protein 25 & P60879 & 8.90E-06 & 3.27E-06 & 2.72 & B\\
\textit{Stxbp1} & Isoform 2 Of Syntaxin-Bind\-ing Protein 1 & O08599 & 1.22E-06 & 0.00E+00 & KI Only & X6\\
\textit{Syt1} & Synaptotagmin 1 & P21579 & 1.02E-05 & 4.81E-06 & 2.13 & B\\
\bottomrule
\end{longtable}

\end{document}

The main measure to take is to enable line breaks for the material in the second column. This can be done by using a p column instead of an l column. (By trial and error, I found that a width of 4.5cm for this column looks about right.)

If all material in the first column has to be italicized, use >{\itshape}l instead of just l for the column type. (This requires loading the array package.) That way, you don't have to encase each entry in a \textit "wrapper" (or, worse, use math mode and render the words in math italics...).

To get typographically appropriate plus and minus symbols in columns 4 and 5, I suggest you load the dcolumn package and align the numbers on the respective decimal markers.

\documentclass{article}
\usepackage{booktabs,geometry,longtable,array,ragged2e,dcolumn}
\geometry{a4paper,total={170mm,257mm},left=20mm,top=20mm}

\begin{document}

\begin{longtable}{@{} >{\itshape}l >{\RaggedRight}p{4.5cm}
l *{2}{D..{1.6}} cc @{}}
&& \multicolumn{4}{c}{Spectral Index} \\
\cmidrule(lr){4-5}
MGI Symbols & \emph{Protein Name} & \emph{UniProt Acc} & \multicolumn{1}{c}{\emph{AveKI}} &
\multicolumn{1}{c}{\emph{AveWT}} &
\emph{KI/WT Ratio} & \emph{Cluster}