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.

There are two vertical lines on top of my table that are not supposed to be there. It looks something like this:

| |

   Table 1: Title

This is the beginning of my code:

\renewcommand{\arraystretch}{1.2}
\begin{table}[h!]

        \centering

            \begin{tabular}{|p{.5in}|C{1.2in}|C{1.4in}|C{1.2in}|} \\

            \multicolumn{4}{c}{\textbf{Table 7: Efficiency Analysis}} \\

            \hline \hline

How do I remove those two vertical lines?

share|improve this question
1  
Please always make a complete, compilable example, not just snippets. And try removing the \\ after \begin{tabular}{..} –  Torbjørn T. Aug 24 at 8:27
    
@TorbjørnT. That `\\` is most likely the cause of the vertical lines.... –  Christian Hupfer Aug 24 at 8:28
    
@Reg You should write \begin{tabular}{p{.5in}|C{1.2in}|C{1.4in}|C{1.2in}} for better result. The outside lines are unnecessary. But please complete the MWE. –  Aradnix Aug 24 at 8:47

1 Answer 1

The simplest solution to getting rid of the unwanted pair of vertical bars is to remove the directive \\ that occurs immediately after \begin{tabular}{...}.

A better -- certainly more elegant -- solution comes from recognizing that you currently don't seem to be using LaTeX's \caption command to generate captions. Instead of typing

\multicolumn{4}{c}{\textbf{Table 7: Efficiency Analysis}} \\

you really ought to just write

\caption{Efficiency Analysis}

Let LaTeX take care of the chores of figuring out the table's number, etc. If you need to have the caption typeset in bold, just load the caption package with the option text=bf. Loading the caption package will also result in the insertion of a bit of vertical whitespace between the caption and the tabular material, creating visual separation of the two elements.

enter image description here

\documentclass{article}
\usepackage[margin=1in]{geometry} % set margins to suit your needs
\usepackage{array,ragged2e}
\usepackage[font=bf]{caption}
\newcolumntype{C}[1]{>{\Centering\arraybackslash}p{#1}}

\begin{document}
Original version, with unwanted pair of vertical bars

\begin{table}[ht!]
\centering
\begin{tabular}{|p{.5in}|C{1.2in}|C{1.4in}|C{1.2in}|} \\
\multicolumn{4}{c}{\textbf{Table 7: Efficiency Analysis}} \\
\hline \hline
a & b & c & d
\end{tabular}
\end{table}

\bigskip
Simple modification: Remove the first \verb+\\+ directive
\begin{table}[ht!]
\centering
\begin{tabular}{|p{.5in}|C{1.2in}|C{1.4in}|C{1.2in}|} 
\multicolumn{4}{c}{\textbf{Table 7: Efficiency Analysis}} \\
\hline \hline
a & b & c & d
\end{tabular}
\end{table}

\bigskip
Better modification: Use the \verb+\caption+ command (\emph{and}  still remove the first \verb+\\+ directive)
\setcounter{table}{6} % just for this example
\begin{table}[ht!]
\caption{Efficiency Analysis}
\centering
\begin{tabular}{|p{.5in}|C{1.2in}|C{1.4in}|C{1.2in}|} 
\hline \hline
a & b & c & d
\end{tabular}
\end{table}
\end{document} 
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.