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

Andy
  • 479

1 Answers1

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}
Mico
  • 506,678