2

I try to make a table with a caption and I have some issues with the layout.

How can I force the table to fit in the width of the caption? The last column is sticking out.

And how could I adjust the alignment in the first column so that z's are one below the other?

\documentclass{article}
\usepackage{longtable}
\usepackage{blindtext}
\begin{document}

\begin{table}[h]
\centering
\caption{\blindtext[1]}
\begin{longtable}{ c | c | c | c | c | c }
 & $0.23< z<13.4$ & $0< z<13.4$ & $0< z<13.4$ & $0.23< z<13.4$ & $0< z<13.4$
\\\hline $0< z<13.4$ & 1000000 & 10000000 & 10000000 & 10000000 & 10000000 
\\\hline $0< z<1$ & 1000000 & 10000000 & 10000000 & 10000000 & 10000000 
\\\hline $0.233< z<1$ & 1000000 & 10000000 & 10000000 & 10000000 & 10000000 
\end{longtable}
\end{table}

\end{document}

enter image description here

5
  • you can't have a longtable inside table Jun 6, 2015 at 9:13
  • but longtable has no caption? how could I try instead?
    – Andy
    Jun 6, 2015 at 9:17
  • 1
    texdoc longtable the documentation says that longtable has a \caption command in the third sentence:-) Jun 6, 2015 at 9:19
  • so is your table long enough to need page breaking (in which case you need longtable and not table, or short enough to be a floating table in which case you need table and tabular and not longtable. Please clarify the question. Jun 6, 2015 at 9:22
  • Just load geometry: you'll have decent margins and this table will fit text width.
    – Bernard
    Jun 6, 2015 at 9:30

1 Answer 1

3

Some suggestions:

  • The main issue that's making the longtable wider than the text block is the material in the header row. To shrink the width of the cells (without outright deletion of any material...), you need to reduce the value of \thickmuskip, the parameter that governs the amount of whitespace that's inserted around the < symbols. In the example below, I set this parameter to 0mu.

  • Reducing the amount of intercolumn whitespace (which is governed by the parameter \tabcolsep) and omitting whitespace entirely at the left-hand and right-hand edges also seems indicated.

  • To get the material in the left-hand column to line up on the z's, I suggest you use a couple of \phantom instructions.

  • Oh, and don't encase a longtable inside a table. The longtable environment provides its own \caption mechanism.

enter image description here

\documentclass{article}
\usepackage{longtable}
\usepackage{blindtext}

\usepackage{etoolbox}
\AtBeginEnvironment{longtable}{%
   \setlength\thickmuskip{0mu}%
   \setlength\tabcolsep{3.7pt}% %% default value is 6pt
   \setlength\LTcapwidth{\textwidth}%
   }
\begin{document}
\hrule  % just to demonstrate width of text block

\begin{longtable}{@{} l | c c c c c @{}}
\caption{\blindtext[1]}\\
& $0.23< z<13.4$ & $0< z<13.4$ & $0< z<13.4$ & $0.23< z<13.4$ & $0< z<13.4$\\
\hline 
\endhead
$0\phantom{.233}< z<13.4$ & 1000000 & 10000000 & 10000000 & 10000000 & 10000000 \\
$0\phantom{.233}< z<1$ & 1000000 & 10000000 & 10000000 & 10000000 & 10000000 \\
$0.233< z<1$ & 1000000 & 10000000 & 10000000 & 10000000 & 10000000 \\
\end{longtable}

\end{document}
2
  • 2
    or perhaps \phantom{.233}0 Jun 6, 2015 at 9:49
  • @DavidCarlisle - That would be good too.
    – Mico
    Jun 6, 2015 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .