# How to format table to fit page

Any suggestions on making the table below? The current set of code makes the table too wide on the page as seen in the second image. I tried putting all of the units on a new row with \\ \hline at the end, but it wasn't working.

\begin{table}[!htbp]
\centering
\caption{Scan parameters for linear ablations of collector probes.}
\label{tab:LAMS}
\begin{tabular}{|cccccc|}
\hline
Laser $$\lambda$$ [nm] & Scan Rate [$$\mu$$m/sec] & Scan Length [mm]
&Pulse Rate [Hz] & Aperture Size [$$\mu$$m] &Energy Density [J/cm2] \\ \hline
213 & 500 & 50-100 & 10 & 55 &  8 \\ \hline
\end{tabular}
\end{table}


Desired:

Current:

The reason for your issues is probably because you wanted to set the units in a row on its own together and they're all set inside [...]. This is falsely interpreted as passing an optional argument to \\. The way to correct for this is by supplying something that is not interpreted as [...] but sets nothing, like \relax or {}:

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\caption{Scan parameters for linear ablations of collector probes.}
\begin{tabular}{ *{6}{c} }
\toprule
Laser $\lambda$ & Scan Rate & Scan Length & Pulse Rate & Aperture Size & Energy Density \\
\relax[nm] & [$\mu$m/sec] & [mm] & [Hz] & [$\mu$m] & [J/cm$^2$] \\
\midrule
213 & 500 & 50-100 & 10 & 55 & 8 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}


The above code also uses booktabs's rules for elegant-looking tables.

I'd use makecell to have multiline column heads, and siunitx for a correct formatting of numbers and units. This is a possible code:

\documentclass[11pt,a4paper,headings=small]{scrartcl}
\usepackage{siunitx}
\usepackage{makecell}
\setcellgapes{4pt}

\begin{document}

\begin{table}[!htbp]
\centering\sffamily
\sisetup{detect-family, range-phrase=--}
\makegapedcells
\setkomafont{captionlabel}{\sffamily}
\setkomafont{caption}{\sffamily}
\captionabove{Scan parameters for linear ablations of collector probes.}
\label{tab:LAMS}
\begin{tabular}{|cccccc|}
\hline
\makecell{Laser $$\lambda$$\\ {[}\si{\nm}]} & \makecell{Scan Rate\\{[}\si{\um\per\s}]} & \makecell{Scan Length\\ {[}\si{\mm}]}
& \makecell{Pulse Rate\\ {[}Hz]} & \makecell{Aperture Size\\ {[}\si{\um}]} & \makecell{Energy Density\\ {[}\si{\J\per\cm^2}]} \\ \hline
213 & 500 & \numrange{50}{100} & 10 & 55 & 8 \\ \hline
\end{tabular}
\end{table}

\end{document}


\relax at the end of the first table line along with \hline at the end of the second seems to have worked.

Here is an additional link to help with \relax: What is the difference between \relax and {}?

\begin{table}[!htbp]
\centering
\caption{Scan parameters for linear ablations of collector probes.}
\label{tab:LAMS}
\begin{tabular}{|cccccc|}
\hline
Laser $$\lambda$$ & Scan Rate  & Scan Length &Pulse Rate & Aperture Size
&Energy Density \\ \relax
[nm] & [$$\mu$$m/sec] &  [mm] & [Hz] &  [$$\mu$$m] & [J/cm2] \\ \hline
213 & 500 & 50-100 & 10 & 55 &  8 \\ \hline
\end{tabular}
\end{table}


Thanks for pointing me in the right direction, Werner.