1

This question might be silly, could've been answered after looking at the Internet, but still, I came here for help.

I want to create a table using LaTeX. The table looks like this:

(3rdExperiment.png)

I was able to manage make a table, but it is not what I envisioned. It looks like this:

(3rdExperiment2.png)

The code I used looks like this:

\documentclass[a4paper,twocolumn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,booktabs}
\usepackage{amssymb}
\usepackage{array}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tabularx,ragged2e,booktabs,caption}
\renewcommand\tabularxcolumn[1]{C{#1}}

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\setlength\parindent{0pt}
\begin{document}

\sffamily\small
\setlength{\tabcolsep}{4pt}
\setlength{\extrarowheight}{2pt}
\noindent
\centering
\begin{tabularx}{\linewidth}{|p{2.0cm}|p{2.0cm}| >{\compress\RaggedRight}X|*{1}{p{21mm}|}}
\hline
Word & Trials & Processing time (in seconds)\\
\hline
%\multirow{2}{=}
{total} & 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
\hline
\end{tabularx}
\label{tab:tab1}
\caption{Tabulated app's responses to different usernames and passwords.}
\end{document}

My question is:

How can we make a table using LaTeX that looks like the first picture above, and more attractive to look at?

1
  • 1
    You are already loading multirow, so why don't you use it for the column "total"?
    – user121799
    Sep 20, 2018 at 4:46

2 Answers 2

2

You don't really need tabularx for this and I removed that. I used a tabular inside a tabular and the m{} columntype to create the table.

The code is:

\documentclass[a4paper,twocolumn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,booktabs}
\usepackage{amssymb}
\usepackage{array}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{ragged2e,booktabs,caption}


\setlength\parindent{0pt}
\begin{document}

\sffamily\small
\setlength{\tabcolsep}{4pt}
\setlength{\extrarowheight}{2pt}
\begin{table}
\centering
\begin{tabular}{|>{\centering\arraybackslash}m{2cm}| >{\centering\arraybackslash}m{3cm} |>{\centering\arraybackslash}m{4cm}|}
\hline
Word & Trials & \begin{tabular}{c}Processing time \\(in seconds)\end{tabular}\\
\hline
\multirow{10}{*}
{``total''} & 1 & Here can be a sentence that will be centered and break automatically  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\cline{2-3}
& 1 & 2 secs  \\
\hline
\end{tabular}
\label{tab:tab1}
\caption{Tabulated app's responses to different usernames and passwords.}
\end{table}
\end{document}

Output:

enter image description here

About the more beautiful (the first rule is to not use vertical lines and if possible not horizontal when not needed.) An example:

\documentclass[a4paper,twocolumn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,booktabs}
\usepackage{amssymb}
\usepackage[table]{xcolor}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{ragged2e,booktabs,caption}


\setlength\parindent{0pt}
\begin{document}

\sffamily\small
\setlength{\tabcolsep}{4pt}
\setlength{\extrarowheight}{2pt}
\begin{table}
\centering
\begin{tabular}{>{\centering\arraybackslash}m{2cm} >{\centering\arraybackslash}m{3cm} >{\centering\arraybackslash}m{4cm}}\arrayrulecolor{red}\toprule
\rowcolor{gray!60}
Word & Trials & \begin{tabular}{c}
Processing time \\(in seconds)\end{tabular}\\\rowcolor{gray!20}\midrule
\cellcolor{gray!40} & 1 & 2 secs \\\rowcolor{gray!40}
&2 & 2 secs  \\\rowcolor{gray!20}
\cellcolor{gray!40}&3 & 2 secs  \\\rowcolor{gray!40}
&4 & 2 secs  \\\rowcolor{gray!20}
\cellcolor{gray!40}&5 & 2 secs  \\\rowcolor{gray!40}
\multirow{-6}{*}{\cellcolor{gray!40}``total''}&6 & 2 secs\\\bottomrule 
\end{tabular}
\label{tab:tab1}
\caption{Tabulated app's responses to different usernames and passwords.}
\end{table}
\end{document}

That gives:

enter image description here

1

Just for fun an option usign tabu, with some options to achieve what you are looking for, it is not very popular because it lacks support since 2011, but I prefer to use it for its clean coding, of course because it is an extension of packages such as tabular, tabularx and array; and as a derivative is limited to its own commands but does not reject commands from the parent libraries.

In this example the width of the lines of the table is varied, which presents a problem for tabu when using multirow, but is fixed by defining a variable for the table line width to be used in each row to correct the gap using \\[-table_line_width], things that are discovered as a user.

RESULT:

enter image description here

MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[a4paper,twocolumn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{booktabs}
\usepackage{amssymb}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{ragged2e,booktabs,caption}
\usepackage[scaled]{helvet}% for sans serif family
\renewcommand\familydefault{\sfdefault} 
%Packages for beautifull tables.
\usepackage{tabu}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{array}
\usepackage[longtable]{multirow}
\usepackage[table]{xcolor}

\usepackage{lipsum} % Dummy text
\begin{document}
\lipsum[1]
\begin{table}[!h]
    \def\TableLineSize{1.5pt}   
    \small
    \tabulinesep = 2.5pt 
    \tabulinestyle{\TableLineSize cyan!50!lime}
    \begin{tabu} to \linewidth {|X[1,mc]|X[1.5,mc]|X[1.5,mc]|} \tabucline -
        \rowcolor{cyan!50!lime!20!white}
        \rowfont[c]{\bf\color{cyan!50!lime!50!black}}
        Word & Trials & Processing time (in seconds)\\ \tabucline -
        \everyrow{\tabucline {2-3}}
        \multirow{10}{*}{Total}
        & 1 & 2 secs  \\[-\TableLineSize]
        & 1 & 2 secs  \\[-\TableLineSize]
        & 1 & 2 secs  \\[-\TableLineSize]
        & 1 & 2 secs  \\[-\TableLineSize]
        & 1 & 2 secs  \\[-\TableLineSize]
        & 1 & 2 secs  \\[-\TableLineSize]
        & 1 & 2 secs  \\[-\TableLineSize]
        & 1 & 2 secs  \\[-\TableLineSize]
        & 1 & 2 secs  \\[-\TableLineSize]
        \everyrow{}
        & 1 & 2 secs  \\ \tabucline -
    \end{tabu}
    \caption{Tabulated app's responses to different usernames and passwords.}
    \label{tab:tab1}
\end{table}

\lipsum[4-9]
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .