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.

The issue that I am having with the image of my longtable is that the caption is not centered and I have vertical lines that appear above my table. I have looked up other posts about my errors but non resolve the issue.

\begin{center}
\begin{longtable}{|c|c|c|}
\centering
\caption{Average Scalar Flux Groups 1 and 2 Test  C} \\
\hline
\rowcolor[gray]{0.85}\textbf{Average Scalar Flux Group 1} 
&\textbf{Average Scalar Flux Group 2} & \textbf{Distance} \\  
\hline
2.185692E-17    &   4.194769E-18        &       0.00 \\ \hline
-1.202652E-04   &   1.202652E-04        &       0.10\\ \hline
-2.405521E-04   &   2.405521E-04        &       0.20\\ \hline
-1.839872E-04   &   1.894445E-04        &       0.30\\ \hline
-1.295853E-04   &   1.403995E-04        &       0.40\\ \hline
-7.678566E-05   &   9.288239E-05        &       0.50\\ \hline
1.078685E-04    &   -1.078685E-04       &       22.30\\ \hline
0.000000E+00    &   0.000000E+00        &       22.40\\ \hline
\label{tlabel}
\end{longtable}
\end{Center}

This is what it looks like. The rest of the table looks fine. It is also cutting off a word in my header above the horizontal line at the top of the page on the left hand side. enter image description here

share|improve this question
    
Welcome to TeX.SE. Please post a MWE always –  Christian Hupfer Apr 20 at 21:47

1 Answer 1

You shouldn't enclose the longtable in a center environment, because the table will be centered by default. Also, \label should go besides the \caption.

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{colortbl,longtable}
\usepackage{lipsum} % just for the example
\begin{document}

\lipsum[2]

\begin{longtable}{|c|c|c|}
\caption{Average Scalar Flux Groups 1 and 2 Test  C}
\label{tlabel} \\
\hline
\rowcolor[gray]{0.85}\textbf{Average Scalar Flux Group 1} 
&\textbf{Average Scalar Flux Group 2} & \textbf{Distance} \\  
\hline
2.185692E-17    &   4.194769E-18        &       0.00 \\ \hline
-1.202652E-04   &   1.202652E-04        &       0.10\\ \hline
-2.405521E-04   &   2.405521E-04        &       0.20\\ \hline
-1.839872E-04   &   1.894445E-04        &       0.30\\ \hline
-1.295853E-04   &   1.403995E-04        &       0.40\\ \hline
-7.678566E-05   &   9.288239E-05        &       0.50\\ \hline
1.078685E-04    &   -1.078685E-04       &       22.30\\ \hline
0.000000E+00    &   0.000000E+00        &       22.40\\ \hline
\end{longtable}

\lipsum[3]
\end{document}

enter image description here

Note that in the standard page setup for the article class the table is too wide, so it will stick in the right margin.

An even better result will be obtained with the help of the siunitx package that's able to format numbers in various ways. Note, in particular, that the hyphens in the preceding example should be minus signs.

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{colortbl,longtable,siunitx}
\usepackage{lipsum} % just for the example

\sisetup{
  output-exponent-marker=\ensuremath{\mathrm{E}},
  exponent-product={},
}

\begin{document}

\lipsum[2]

\begin{longtable}{
  |S[table-format=-1.6e-2]|
   S[table-format=-1.6e-2]|
   S[table-format=2.2]|
}
\caption{Average Scalar Flux Groups 1 and 2 Test  C}
\label{tlabel} \\
\hline
\rowcolor[gray]{0.85}\textbf{Average Scalar Flux Group 1}
&\textbf{Average Scalar Flux Group 2} & \textbf{Distance} \\  
\hline
2.185692E-17    &   4.194769E-18        &       0.00 \\ \hline
-1.202652E-04   &   1.202652E-04        &       0.10\\ \hline
-2.405521E-04   &   2.405521E-04        &       0.20\\ \hline
-1.839872E-04   &   1.894445E-04        &       0.30\\ \hline
-1.295853E-04   &   1.403995E-04        &       0.40\\ \hline
-7.678566E-05   &   9.288239E-05        &       0.50\\ \hline
1.078685E-04    &   -1.078685E-04       &       22.30\\ \hline
0.000000E+00    &   0.000000E+00        &       22.40\\ \hline
\end{longtable}

\lipsum[3]
\end{document}

enter image description here


You should also consider this possible enhancement, that avoids many problems both in readability and in horizontal spacing.

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{longtable,siunitx,booktabs}
\usepackage{lipsum} % just for the example

\sisetup{output-exponent-marker=\ensuremath{\mathrm{E}},exponent-product={}}

\begin{document}

\lipsum[2]

\begin{longtable}{
  S[table-format=-1.6e-2]
  S[table-format=-1.6e-2]
  S[table-format=2.2]
}
\caption{Average Scalar Flux Groups 1 and 2 Test  C}
\label{tlabel} \\
\toprule
\multicolumn{2}{c}{\textbf{Average Scalar Flux}} & {\textbf{Distance}} \\
\cmidrule{1-2}
{\textbf{Group 1}} & {\textbf{Group 2}} & \\
\midrule
 2.185692E-17 &  4.194769E-18 &  0.00 \\
-1.202652E-04 &  1.202652E-04 &  0.10 \\
-2.405521E-04 &  2.405521E-04 &  0.20 \\
-1.839872E-04 &  1.894445E-04 &  0.30 \\
-1.295853E-04 &  1.403995E-04 &  0.40 \\
-7.678566E-05 &  9.288239E-05 &  0.50 \\
 1.078685E-04 & -1.078685E-04 & 22.30 \\
 0.000000E+00 &  0.000000E+00 & 22.40 \\
\bottomrule
\end{longtable}

\lipsum[3]
\end{document}

enter image description here

share|improve this answer
    
shouldn't those negative indicators in the table be minuses instead of hyphens? –  barbara beeton Apr 21 at 5:34
    
@barbarabeeton Thanks for noticing. I uploaded a better version with siunitx –  egreg Apr 21 at 9:06

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.