Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My code is as follows,

\documentclass{article} 
\usepackage{amsmath, amssymb}
\usepackage{setspace} 
\usepackage{ulem}
\usepackage{float} % fix the table
\usepackage{bold-extra}
\usepackage{amsmath,bm}
\usepackage[margin=1in]{geometry} 
\usepackage{color}
\usepackage{amsmath,amsopn}
\usepackage{bbm}
\usepackage{import}
\usepackage{hyperref} 
\usepackage[Sonny]{fncychap}
\usepackage{mathrsfs}
\usepackage{tikz,pgfplots}
\usepackage{listings}
\usepackage{fancyhdr}
\usepackage{color}
%\usepackage{breqn} 
\usepackage{caption}
\usepackage{subcaption}
\usepackage{epstopdf}
\usepackage[titletoc,toc,title]{appendix}
\usepackage{mathtools}

\begin{document} 
\begin{table}

\begin{subtable}{\textwidth}
\centering
    \label{tab mtl a ins5}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|}
\hline

$10^{-2}$ &  5373   &  4248 &3137 & 2029  & 996     &  651 &  488    & 455   &  481                 &   575    &  659     &491    \\
      &  378(m) &  299(m) &221(m) & 143(m)  & 70(m)     &  46(m) &  34(m)    & 32(m)       &  34(m)     &   40(m)    &  46(m)     &35(m)    \\\hline
$10^{-5}$ & -      & -     &93712 &59616  & 25353    & 9737  & 19597   & 37621&  55079  &72379    &  90438    &84164 \\
      &        &       &6591(m) &4193(m)  & 1783(m)    & 685(m)  & 1378(m)   & 2646(m)&      3874(m)  &5091(m)    &  6361(m)    &5920(m) \\\hline
$10^{-8}$ & -      &   -   &  -    &-      &  -       &34076  &69287   & -      & -     & -        & -     &-\\
      &        &       &       &       &          &2397(m)  &4873(m)   &        &       &          &       & \\\hline
\end{tabular}
\end{subtable}
\end{table}

\end{document}

enter image description here

As the litter image, this line of the table is two long. So I want to shorten the space in each entry horizontally.

Thank you in advance!

share|improve this question
1  
Could you provide a MWE showing packages and preamble you're using. Also, I'm not aware of any use of the table environment which takes a mandatory argument for setting its size. –  A.Ellett Oct 27 '13 at 17:59
1  
I would remove the (m) and put it as a header; would you please add the data to the MWE as per image? –  Yiannis Lazarides Oct 27 '13 at 18:01
    
@A.Ellett, Thank you for your comment. I cannot to know what's mean MWE by google? Could you tell me? –  Vivian Oct 27 '13 at 18:03
    
@YiannisLazarides, thank you. I think it a easy way but it is useful. –  Vivian Oct 27 '13 at 18:03
    
See What makes a good MWE? –  A.Ellett Oct 27 '13 at 18:05

3 Answers 3

up vote 3 down vote accepted

This is my solution with default margins in a4paper without splitting or turn the table (I also recommend this in first place, anyway):

\documentclass[a4paper]{article} 
\usepackage{lipsum} % dummy text to see text width  
\usepackage{tabularx}
\newcolumntype{Y}{>{\footnotesize\raggedleft\arraybackslash}X}
\setlength{\tabcolsep}{0pt}
\usepackage{booktabs}

\begin{document} 
\lipsum[2]\bigskip

    \noindent\begin{tabularx}{\textwidth}{YYYYYYYYYYYYY}
    \toprule
    $10^{-2}$ & 5373 & 4248 & 3137 & 2029 & 996 & 651 & 488 & 455 & 481 & 575 & 659 & 491 \\
     (m) & 378 & 299 & 221 & 143 & 70 & 46 & 34 & 32 & 34 & 40 & 46 & 35 \\\midrule
    $10^{-5}$ & --- & --- & 93712 & 59616 & 25353 & 9737 & 19597 & 37621 & 55079 & 72379 & 90438 & 84164 \\
     (m) & & & 6591 & 4193 & 1783 & 685 & 1378 & 2646 & 3874 & 5091 & 6361 & 5920 \\\midrule
    $10^{-8}$ & --- & --- & --- & --- & --- & 34076 & 69287 & --- & --- & --- & --- & ---\\
     (m) & & & & & & 2397 & 4873 & & & & & \\\bottomrule
    \end{tabularx}

\bigskip\lipsum[3]
\end{document}

MWE

Edit: As requested, the next is the same table without the Lore ipsum text and with a caption. The standard method is to use \caption{} inside a table environment, that is floating object (more or less , depending of the options). If you want a caption but not a floating table in any circumstance, see the capt-of or captionof packages. I added also a label, with some indications about where to place and how to use (cross-reference) since it was not well placed in the question.

\documentclass[a4paper]{article} 
\usepackage{tabularx} 
\newcolumntype{Y}{>{\footnotesize\raggedleft\arraybackslash}X}
\setlength{\tabcolsep}{0pt} 
\usepackage{booktabs} % for nice rules in tables
% \usepackage[colorlinks]{hyperref} % uncomment and compile twice to have a reference link
\begin{document} 

\begin{table}[h] % change [h] to [htbp] for free float 

\caption{Some explanatory caption}
\label{tab:longtable} % remark: use meaningful and simple labels

\begin{tabularx}{\textwidth}{YYYYYYYYYYYYY}
    \toprule
    $10^{-2}$ & 5373 & 4248 & 3137 & 2029 & 996 & 651 & 488 & 455 & 481 & 575 & 659 & 491 \\
     (m) & 378 & 299 & 221 & 143 & 70 & 46 & 34 & 32 & 34 & 40 & 46 & 35 \\
     \midrule
    $10^{-5}$ & --- & --- & 93712 & 59616 & 25353 & 9737 & 19597 & 37621 & 55079 & 72379 & 90438 & 84164 \\
     (m) & & & 6591 & 4193 & 1783 & 685 & 1378 & 2646 & 3874 & 5091 & 6361 & 5920 \\
     \midrule
    $10^{-8}$ & --- & --- & --- & --- & --- & 34076 & 69287 & --- & --- & --- & --- & ---\\
     (m) & & & & & & 2397 & 4873 & & & & & \\
     \bottomrule
\end{tabularx}

\end{table}

Some text with a reference to table \ref{tab:longtable}. This reference need the label inside \texttt{table}, always under the caption (\verb|\caption{}\label{}|) or inside the caption (e.g. \verb|\caption{\label{}}|). 

\end{document}

MWE2

share|improve this answer
    
Thank you for your answer. I use your method. But this method will automatically generate some text, some words. Like 'Nulla malesuada....' How could I avoid this stuff? –  Vivian Oct 29 '13 at 13:21
    
How could I add caption? Thank you in advance! –  Vivian Oct 29 '13 at 13:23
    
@Vivian, see the edited answer. –  Fran Oct 30 '13 at 0:20

You're duplicating many calls to the same packages such as amsmath.

The approach I would take with a table that's difficult to fit on a page is to import it from a standalone copy.

I would start by creating a file, for the purposes of this example I just call this table_01.tex:

\documentclass{standalone}
\begin{document}

\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|}
\hline
$10^{-2}$ & 5373   & 4248   & 3137    & 2029    & 996     & 651     & 488     & 455     & 481     & 575     & 659     & 491      \\
          & 378(m) & 299(m) & 221(m)  & 143(m)  & 70(m)   & 46(m)   & 34(m)   & 32(m)   & 34(m)   & 40(m)   & 46(m)   & 35(m)    \\\hline
$10^{-5}$ & -      & -      & 93712   & 59616   & 25353   & 9737    & 19597   & 37621   & 55079   & 72379   & 90438   & 84164    \\
          &        &        & 6591(m) & 4193(m) & 1783(m) & 685(m)  & 1378(m) & 2646(m) & 3874(m) & 5091(m) & 6361(m) & 5920(m)  \\\hline
$10^{-8}$ & -      & -      & -       & -       & -       & 34076   & 69287   & -       & -       & -       & -       & -        \\
          &        &        &         &         &         & 2397(m) & 4873(m) &         &         &         &         &          \\\hline
\end{tabular}

\end{document}

Compile using pdflatex.

I would then use the graphicx package to import the standalone as follows

\documentclass{article} 
\usepackage[margin=1in]{geometry} 
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document} 

\begin{table}
\begin{subtable}{\textwidth}
\centering
    \label{tab mtl a ins5}
  \includegraphics[width=\textwidth]{table_01}
\end{subtable}
\caption{my table}
\end{table}

\end{document}

There are short-comings to this approach. Namely, the font size in the imported image will be different from that in the many body of the text. So, this is perhaps a solution of last resort.

Otherwise, if this is not a suitable approach I might recommend splitting the table into two parts:

\documentclass{article} 
\usepackage[margin=1in]{geometry} 
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document} 

\begin{table}
\begin{subtable}{\textwidth}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
$10^{-2}$ & 5373    & 4248    & 3137    & 2029    & 996     & 651      \\
          & 378(m)  & 299(m)  & 221(m)  & 143(m)  & 70(m)   & 46(m)    \\\hline
$10^{-5}$ & -       & -       & 93712   & 59616   & 25353   & 9737     \\
          &         &         & 6591(m) & 4193(m) & 1783(m) & 685(m)   \\\hline
$10^{-8}$ & -       & -       & -       & -       & -       & 34076    \\
          &         &         &         &         &         & 2397(m)  \\\hline
\hline
$10^{-2}$ & 488     & 455     & 481     & 575     & 659     & 491      \\
          & 34(m)   & 32(m)   & 34(m)   & 40(m)   & 46(m)   & 35(m)    \\\hline
$10^{-5}$ & 19597   & 37621   & 55079   & 72379   & 90438   & 84164    \\
          & 1378(m) & 2646(m) & 3874(m) & 5091(m) & 6361(m) & 5920(m)  \\\hline
$10^{-8}$ & 69287   & -       & -       & -       & -       & -        \\
          & 4873(m) &         &         &         &         &          \\\hline
\end{tabular}
\end{subtable}
\caption{my table}
\end{table}

\end{document}

enter image description here

You might try using the booktabs package. Even if you don't use this package, you might consider its advice to avoid using vertical lines in tables. The effect can be very nice:

\documentclass{article} 
\usepackage[margin=1in]{geometry} 
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{graphicx}
\begin{document} 

\begin{table}
\begin{subtable}{\textwidth}
\setlength{\tabcolsep}{1em}
\setlength{\doublerulesep}{1ex}
\centering
\begin{tabular}{ccccccc}
\toprule
$10^{-2}$ & 5373    & 4248    & 3137    & 2029    & 996     & 651      \\
          & 378(m)  & 299(m)  & 221(m)  & 143(m)  & 70(m)   & 46(m)    \\\midrule
$10^{-5}$ & --      & --      & 93712   & 59616   & 25353   & 9737     \\
          &         &         & 6591(m) & 4193(m) & 1783(m) & 685(m)   \\\midrule
$10^{-8}$ & --      & --      & --      & --      & --      & 34076    \\
          &         &         &         &         &         & 2397(m)  \\\midrule\midrule
$10^{-2}$ & 488     & 455     & 481     & 575     & 659     & 491      \\
          & 34(m)   & 32(m)   & 34(m)   & 40(m)   & 46(m)   & 35(m)    \\\midrule
$10^{-5}$ & 19597   & 37621   & 55079   & 72379   & 90438   & 84164    \\
          & 1378(m) & 2646(m) & 3874(m) & 5091(m) & 6361(m) & 5920(m)  \\\midrule
$10^{-8}$ & 69287   & --      & --      & --      & --      & --       \\
          & 4873(m) &         &         &         &         &          \\\bottomrule
\end{tabular}
\end{subtable}
\caption{my table}
\end{table}

\end{document}

enter image description here

For this last example, I changed how the dashes from - to --.

Yet another idea is to create a new column type for which you can specify the column width, and centers its content both horizontally and vertically. For this you will need to use the array package.

\documentclass{article} 
\usepackage[margin=1in]{geometry} 
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{array}
\usepackage{graphicx}
%% Define a new column type `M`
%% the \let\nl\\ allows you to explicitly insert new lines using \nl
%% \arraybackslash allows you to terminate the row with \\ even if the immediately preceding column is of type `M`
\newcolumntype{M}[1]{>{\centering\let\nl\\\arraybackslash}m{#1}}
\begin{document} 

\begin{table}
\begin{subtable}{\textwidth}
\setlength{\tabcolsep}{1em}
\setlength{\doublerulesep}{1ex}
\centering
\begin{tabular}{m{1cm}*{6}{M{1.25cm}}}
\toprule
$10^{-2}$ & 5373\nl 378(m)   & 4248\nl 299(m)   & 3137\nl221(m)    & 2029\nl 143(m)   & 996\nl70(m)      & 651\nl46(m)      \\\midrule
$10^{-5}$ & --               & --               & 93712\nl6591(m)  & 59616\nl4193(m)  & 25353\nl1783(m)  & 9737\nl685(m)    \\\midrule
$10^{-8}$ & --               & --               & --               & --               & --               & 34076\nl 2397(m) \\\midrule\midrule
$10^{-2}$ & 488\nl 34(m)     & 455\nl 32(m)     & 481\nl 34(m)     & 575\nl 40(m)     & 659\nl 46(m)     & 491\nl 35(m)     \\\midrule
$10^{-5}$ & 19597\nl 1378(m) & 37621\nl 2646(m) & 55079\nl 3874(m) & 72379\nl 5091(m) & 90438\nl 6361(m) & 84164\nl 5920(m) \\\midrule
$10^{-8}$ & 69287\nl 4873(m) & --               & --               & --               & --               & --               \\\bottomrule
\end{tabular}
\end{subtable}
\caption{my table}
\end{table}

\end{document}

enter image description here

share|improve this answer

Assuming you have "letterpaper" paper (8.5" by 11") rather than A4-paper and 1" margins, a combination of \setlength\tabcolsep{3pt} (default is 6pt) and \footnotesize -- both instructions to be inserted right after \begin{table} -- will succeed in making the table fit inside the textblock, which will be 6.5" wide under the assumptions given above.

This is how your table would look like (the vertical bars at the far left and right denote the edges of the text block):

enter image description here

A combination of \setlength\tabcolsep{2pt} and \small will also succeed in fitting the table inside the text block:

enter image description here

Your preferences over intercolumn whitespace vs. font size of the material in the table should determine if this combination is better than \setlength\tabcolsep{3pt} / \footnotesize.

You should really consider simplifying the material in the cells. For instance, even if you just replaced all (m) terms with m (i.e., if you omitted the parentheses), you'd save so much space that you wouldn't even have to reduce the font size, while still allowing a somewhat-generous \setlength\tabcolsep{3pt} setting, and still fit the table into the text block:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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