11
\begin{table}[htbp]
        \centering
        \small
        \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
            \hline
                Wavelength & Model & Package & Emmitter type & Manufacturer & Power (mW) & Iop (mA) & Ith (mA) & Vop (V)\\
            \hline
                405 & DL-7386-101HG & TO-56 & single & sanyo & 50-70 & 70 & 35 & 4.8\\
            \hline
                450 & PL 450 & TO-38 & single & osram & 50-90 & 120 & 30 & 5.5\\
            \hline
                638 & ML520G54 & TO-56 & single & mitsubishi & 90-100 & 150 & 50 & 2.7\\
            \hline
                655 &  DL-5147-242 & TO-56 & single & sanyo & 30-50 & 80 & 40 & 3.8\\
            \hline
        \end{tabular}
        \caption{Laser specifications}
        \label{tab:Laser_Specs}
    \end{table}

The above is my code for creating a table and when compiled it gets beyond textwidth. How can I solve this issue without altering the font size ? Output!

Moriambar
  • 11,466
Rene Duchamp
  • 1,491
  • A few ideas (besides splitting the table up or rotating it): cells with more than one line (possible the long headings) or tabularxX column. Removing the unnecessary vertical lines or reducing \tabcolsep, the space between columns, could also be a solution. Could you add a full minimal working example? – Qrrbrbirlbel Jun 25 '13 at 19:41
  • 1
    How about swapping columns and rows?? –  Jun 25 '13 at 19:36
  • I can but not the right way to present such data. – Rene Duchamp Jun 25 '13 at 20:23

1 Answers1

12

Please always post complete documents as for example the text width is important here and that can not be seen in your fragment.

enter image description here

\documentclass[a4paper]{article}

\usepackage{array}
\setlength\extrarowheight{2pt}

\begin{document}

\begin{table}[htbp]
        \centering
        \small
        \setlength\tabcolsep{2pt}
        \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
            \hline
              Wave- &        &           & Emmitter & Manu- & Power & Iop & Ith  & Vop \\[-3pt]% compensate for extrarowheight
               length& Model &    Package & type &  facturer & (mW) & (mA) &  (mA) & (V)\\
            \hline
                405 & DL-7386-101HG & TO-56 & single & sanyo & 50--70 & 70 & 35 & 4.8\\
            \hline
                450 & PL 450 & TO-38 & single & osram & 50--90 & 120 & 30 & 5.5\\
            \hline
                638 & ML520G54 & TO-56 & single & mitsubishi & 90--100 & 150 & 50 & 2.7\\
            \hline
                655 &  DL-5147-242 & TO-56 & single & sanyo & 30--50 & 80 & 40 & 3.8\\
            \hline
        \end{tabular}
        \caption{Laser specifications}
        \label{tab:Laser_Specs}
    \end{table}

\noindent X\dotfill X


\end{document}
David Carlisle
  • 757,742
  • the column headers would look nicer as bottom-aligned, centered "paragraphs"; the space between the lines is so wide that it makes these headers hard to read. – barbara beeton Jun 25 '13 at 20:20
  • @barbarabeeton yes I know. What you mean I suspect is not that that would look nicer, but rather that I should edit the answer to make it so... – David Carlisle Jun 25 '13 at 20:23
  • indeed -- that is exactly what i mean. (would make the answer much more useful.) – barbara beeton Jun 25 '13 at 20:29
  • @barbarabeeton your wish is... – David Carlisle Jun 25 '13 at 20:29
  • Does this answer the question? I only see a big chunk of code. – Zimano Mar 31 '20 at 11:27
  • @Zimano sorry I don't understand your comment. There is very little code other than the text of the table as supplied in the question, reformatted as requested to fit in the page width. – David Carlisle Mar 31 '20 at 11:38
  • @DavidCarlisle I'm not used to code-only answers (I come from SO). Usually, an answer should minimally include what was changed, which new commands were introduced etc. Someone looking for the answer first has to lay OP's code and your code together and try and spot the differences by eye. You might want to explain that things like \setlength\tabcolsep{2pt} are what worked for you to achieve OP's desired result. – Zimano Mar 31 '20 at 12:49
  • @Zimano on SO the question would probably have been closed as unclear and not answered at all since it lacked a real example so I wouldn't take comparisons with SO to seriously, we are a lot more forgiving of poorly constructed questions on this site. But anyway this question is 7 years old and closed as a duplicate (one of hundreds of duplicates of this question on this site) so not sure why you are commenting on it now? – David Carlisle Mar 31 '20 at 12:59
  • 2
    @DavidCarlisle You seem to imply that incomplete/low-quality answers are OK just because the question was a duplicate / was closed / was not asked on SO.If that is indeed your trail of thought, then I have to disagree. Answers should contain some explanation, and yours doesn't provide any. It's simply a blob of code where a reader is left to find the differences. – Zimano Mar 31 '20 at 13:35