2

I am trying to create a table using the following code:

\begin{center}
\begin{table}[h!]
\begin{tabular}{|l|l|l|l|}\hline \\
Test users  &  Operating system & Browser & Screen resolution\\ \\ \hline
Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050\\ \hline
Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050\\ \hline
Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050\\ \hline
\end{tabular}
\caption{Test environment details}
\label{Test-environment-details}
\end{table}
\end{center}

What I get from this is shown below: enter image description here Why the vertical lines missing in column 2,3 and 4? Thanks

  • 2
    you have \hline \\ and \\ \\ so those table rows are cut short with just the first column, don't do that. – David Carlisle Dec 22 '14 at 12:47
  • 2
    Unrelated but don't use [h!] laTex will usually warn about this and change it to !ht] but using [htp] is better, otherwise it is just increasing the chance that the table floats to the end of the document. – David Carlisle Dec 22 '14 at 12:48
  • 2
    Also unrelated do not put a center environment around table it will have no effect on the alignment but will produce anomolous vertical space at that point even though the table may float and be set wheresoever else. – David Carlisle Dec 22 '14 at 12:50
  • 3
    you could get rid of the vertical lines and use booktabs package \toprule and \midrule which have vertical space around them, or you could use \\[.5em] to add space after a row, to add space after an \hline` is a bit harder perhaps add something like \rule{0pt}{2cm} into the first cell, or whatever height you need – David Carlisle Dec 22 '14 at 13:02
  • 1
    Also note that you can use $1680 \times 1050$ to typeset your screen resolutions more nicely. – wchargin Dec 22 '14 at 16:12
7

Another way to get the table as you'd like it is

\begin{table}[h!]
    \begin{tabular}{|l|l|l|l|}\hline & & &  \\
        Test users  &  Operating system & Browser & Screen resolution\\ & & &  \\ \hline
        Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050\\ \hline
        Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050\\ \hline
        Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050\\ \hline
    \end{tabular}
    \caption{Test environment details}
    \label{Test-environment-details}
\end{table}

You have to add the & to separate the cells even if you want a blank line. Otherwise the vertical lines will not be drawn for these rows.

result

As @David Carlisle recommended, the booktabs package allows to typeset tables with a nicer spacing. I usually use booktabs for all formal tables. A MWE would be

\documentclass{article}
\usepackage{booktabs}
\begin{document}
    \begin{table}[htbp]
    \begin{tabular}{llll}\toprule
        Test users  &  Operating system & Browser & Screen resolution\\ \midrule
        Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050\\
        Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050\\
        Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050\\ \bottomrule
    \end{tabular}
    \caption{Test environment details}
    \label{Test-environment-details}
    \end{table}
\end{document}

which produces

enter image description here

8

Here's how to obtain the table you wanted:

\documentclass{article}
\usepackage{array}

\begin{document}
\begin{table}[!htbp]
\begin{tabular}{|m{1.8cm}|m{2.8cm}|m{2.5cm}|m{2.8cm}|@{}m{0pt}@{}}
\hline 
Test users  &  Operating system & Browser & Screen resolution &\\[15pt]\hline
Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050 &\\ \hline
Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050 &\\ \hline
Test user 1 & Win 7 pro & Mozilla firefox & 1680X1050 &\\ \hline
\end{tabular}
\caption{Test environment details}
\label{Test-environment-details}
\end{table}
\end{document} 

enter image description here

Some comments:

  • Thanks but can you please explain what is going on here \begin{tabular}{|m{1.8cm}|m{2.8cm}|m{2.5cm}|m{2.8cm}|@{}m{0pt}@{}} :) – ρss Dec 22 '14 at 13:04
  • @ρss Of course. Added some comments (I was on the rush...) – karlkoeller Dec 22 '14 at 13:19

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.