1

I have pages of table so I start to use longtable. My LaTeX input is given below. Even I use same code for each column, only first column is left aligned.

\renewcommand*{\arraystretch}{1}


\begin{center}  
\small  % Switch from 12pt to 11pt; otherwise, table won't fit  
\setlength\LTleft{0pt}           % default: \parindent  
\setlength\LTright{0pt}           % default: \fill  
\begin{longtable}{@{\extracolsep{\fill}}|l|l|l|l|l|l|}  
\caption[First Part Optimization Results]{First Part Optimization Results}  
 \label{grid_mlmmh} \\  

\hline \multicolumn{6}{|c|}{Initial Points} \\ \hline     
\endfirsthead  

\multicolumn{6}{c}%  
{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\  
\hline \multicolumn{1}{|l|}{Angle Thk} &  
\multicolumn{1}{l|}{Angle Ht} &  
\multicolumn{1}{l|}{Base Thk} &  
\multicolumn{1}{l|}{Bracket Thk} &  
\multicolumn{1}{l|}{Beam Thk} &  
\multicolumn{1}{l|}{Maximum RF} \\ \hline   
\endhead  

\hline \multicolumn{6}{r}{Continued on next page} \\  
\endfoot  

\endlastfoot  

% \hline  
Angle Thk & Angle Ht & Base Thk & Bracket Thk & Beam Thk & Maximum RF             \\ \hline  
2 & 10 & 4 & 8 & 2 & 41212 \\ \hline  
2 & 9 & 6 & 1  & 8 & 51047 \\ \hline  
4 & 12 & 6 & 3 & 7 & 91721 \\ \hline  
7 & 14 & 3 & 2 & 6 & 135734 \\ \hline  

Not exactly aligned right, but there is space at the remaining columns. Heading and numbers are not ordinate.

Thanks for help.

The result is like this,

  • Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – Heiko Oberdiek Jul 29 '17 at 9:56
  • Take a look at package siunitx for aligning numbers in a table. Also, package booktabs is worth a look to remove the number of lines. – Heiko Oberdiek Jul 29 '17 at 9:58
  • How many times did you run LaTeX on that code? In general longtable needs more than one run to get alignment of columns right. Also, could you please make your code a complete MWE beginning at \documentclass and ending at \end{document} including all (but no more) packages needed to compile and reproduce your issue? – Skillmon Jul 29 '17 at 10:07
  • 1
    your image shows all columns left aligned. Also never put longtable in a center environment. – David Carlisle Jul 29 '17 at 11:47
1

The numbers can be aligned with package siunitx. Then the table heads are usually centered. Also, the following example uses package booktabs to show, how a table can be drawn with few horizontal lines only.

The example has stripped off the longtable stuff, because it is not needed to show the alignment with siunitx.

The table headers are formatted in two lines, because a comment said that the width of the table is a concern.

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\newcommand*{\cell}[1]{\begin{tabular}[b]{@{}c@{}}#1\end{tabular}}
\begin{tabular}{
  S[table-format=1.0]
  S[table-format=2.0]
  S[table-format=1.0]
  S[table-format=1.0]
  S[table-format=1.0]
  S[table-format=6.0]
}
\toprule
%\multicolumn{6}{c}{Initial Points} \\
%\midrule 
{\cell{Angle\\Thk}} &  
{\cell{Angle\\Ht}} &  
{\cell{Base\\Thk}} &  
{\cell{Bracket\\Thk}} &  
{\cell{Beam\\Thk}} &  
{\cell{Maximum\\RF}} \\
\midrule
2 & 10 & 4 & 8 & 2 & 41212 \\
2 & 9 & 6 & 1  & 8 & 51047 \\
4 & 12 & 6 & 3 & 7 & 91721 \\
7 & 14 & 3 & 2 & 6 & 135734 \\
\bottomrule
\end{tabular}
\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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