# Need help to make a table

I need to make a table which looks like .

I have written my code below.

\documentclass[12pt]{article}


\usepackage{latexsym}

\usepackage{amsmath, times, amsfonts, mathrsfs, amssymb}
\begin{document}
\begin{table}[ht]
\caption{\small Comparison results}
\small
\centering
\hline
\begin{tabular}{c c c c c c c c }
\hline
$\beta$ & step & $\|A^{(2)}_{T,S} - X_k\|_2$ & $\|X_k - X_{k-1} \|_2$  & $\|A^{(2)}_{T,S} - X_k\|_2$ & $\|X_k - X_{k-1} \|_2$ \\
\hline
&   &      &      &  &\\[1ex]

\hline
\end{tabular}
\label{table:nonlin}
\end{table}
\end{document}


I am finding it difficult to draw horizontal lines for $t =1$ and $t = 2$, which should be similar to the attached image file. I need help to draw this table. Thank you very much for your time.

• Your code does not compile. – cfr Nov 16 '14 at 4:14

booktabs makes this easier here:

\documentclass[12pt]{article}

\usepackage{latexsym}
\usepackage{booktabs}
\usepackage{amsmath, amsfonts, mathrsfs, amssymb}
\usepackage{mathptmx}% times is deprecated
\usepackage[scaled=.90]{helvet}
\usepackage{courier}

\begin{document}
\begin{table}[ht]
\caption{\small Comparison results}
\small
\centering
\begin{tabular}{ *{8}{c} }
\toprule
$\beta$ & step & $\|A^{(2)}_{T,S} - X_k\|_2$ & $\|X_k - X_{k-1} \|_2$  & $\|A^{(2)}_{T,S} - X_k\|_2$ & $\|X_k - X_{k-1} \|_2$ \\\cmidrule(lr){3-4}\cmidrule(lr){5-6}
&   &      &      &  &\\[1ex]
\bottomrule
\end{tabular}
\label{table:nonlin}
\end{table}
\end{document}


Note that times is deprecated and ought not be used.

• @srijan You are welcome. But Mico's answer might suit your needs better and is more comprehensive. (The method to get the horizontal lines, which is the focus of your question, is the same, but Mico also uses array which might be a better option.) However, that is a matter for your judgement - only you can say which answer you find most helpful ;). – cfr Nov 16 '14 at 17:53

I would suggest you do the following:

• Since almost all of the table's material should be typeset in math mode, use an array environment instead of a tabular environment. This will save you from having to type lots and lots of $ symbols (one pair per cell). • Load the booktabs package and use its macros to obtain well-spaced horizontal lines. Use the \cmidrule macro (with optional left-hand and right-hand trimming) for the intermediate lines. • If you want the caption as well as the remainder of the table to be set in "small", load the caption package and issue the command \captionsetup{font=small}. You can do this either at the start of the table, if the sizing command should pertain to only that table, or globally in the preamble if all figure and table captions of the document should be set in "small" size. • Load the mathtools package and define a macro named \norm. This will save you a lot of typing of \| directives. • As others have already pointed out, the times package is deprecated. Load either the mathptmx package or (my preference) the newtxtext and newtxmath packages. \documentclass[12pt]{article} %\usepackage{latexsym} %% latexsym is really ancient \usepackage{booktabs} \usepackage{amsfonts, mathrsfs, amssymb} \usepackage{mathtools} % loads amsmath, provides extra macros \DeclarePairedDelimiter\norm{\lVert}{\rVert} \usepackage{newtxtext,newtxmath} % times is deprecated \usepackage{caption} % to influence size of caption \begin{document} \begin{table}[ht] \small \captionsetup{font=small} \caption{Results for Example 4.1 using the iteration (3) for$t=1,2$} \label{table:nonlin} \centering$\begin{array}{ @{} ll *{4}{c} @{}}
\toprule
\beta & \text{Step}
& \multicolumn{2}{c}{t=1}
& \multicolumn{2}{c}{t=2} \\
\cmidrule(lr){3-4}\cmidrule(l){5-6}
& & {\norm{A^{(2)}_{T,S} - X_k}_2}
& {\norm{X_k - X_{k-1}}_2}
& {\norm{A^{(2)}_{T,S} - X_k}_2}
& {\norm{X_k - X_{k-1}}_2} \\
\midrule
0.9 & k=31 & 6.1424{e-}008 & 5.0256{e-}008\\
\bottomrule
\end{array}\end{table} \end{document}  • You can also use tools like truben.no/table or tablesgenerator.com to make almost all the boring work. :-) – Smarzaro Nov 16 '14 at 12:39 • @Smarzaro - Will tablegenerator.com know to use an array instead of a tabular environment? – Mico Nov 16 '14 at 12:59 • No. It uses tabular. But it can make easy to merge cells and put the borders the way he wants. It does not do all the work, but it's a good start... Very useful. – Smarzaro Nov 16 '14 at 13:15 • @Smarzaro - As the OP's table has no borders (vertical bars) to begin with, he/she doesn't need help in that regard, right? The OP's main question was about getting the two short horizontal lines; does tablegenerator.com know about \cmidrule and, in particular, how to perform left- and right-trimming of such rules? – Mico Nov 16 '14 at 13:19 • Sorry, with "borders" I mean all the lines, including the horizontal ones. Yes, it uses the booktabs and cmidrule. As one of the difficuties pointed by the question, I think it worthed mention this kind of tool. – Smarzaro Nov 16 '14 at 13:27 As suggested here how you can use the tablesgenerator to build the initial structure for the table. 1. Create the new table (file->new) 1. Merge the cells on the header 1. Do some typing of the contents (I put f1 to f4to speed up, and it´s easier do it on LaTeX editor) 1. Set the alignment. 1. Set the table to use booktabs style 1. Activate custom grid edit to add or remove some borders 1. Click generate to refresh the code. 1. The result can be seen below. The original result from tablesgenerator is the top image, and the bottom is the result after some adjust. As I said the services like tables generator does not do all the work, but it helps. The code \usepackage{latexsym} \usepackage{amsmath, times, amsfonts, mathrsfs, amssymb} \usepackage{booktabs} \begin{document} % Please add the following required packages to your document preamble: % \usepackage{booktabs} \begin{table}[h] \centering \caption{My caption} \label{my-label} \begin{tabular}{@{}cccccc@{}} \toprule & & \multicolumn{2}{c}{t = 1} & \multicolumn{2}{c}{t = 2} \\ \cmidrule(l){3-6} \beta & Step & f1 & f2 & f3 & f4 \\ \midrule 0.9 & k=31 & 6.1424e-008 & 5.0256e-008 & 8.1170e-016 & 1.3257e-015 \\ & k=32 & 3.3783e-008 & 2.7641e-008 & 7.0439e-016 & 3.1839e-016 \\ \bottomrule \end{tabular} \end{table} % Table after some adjustments % 1 - Split \cmidrule in two % 2 - Change tabular to array to avoid put on the math
% 3 - Replace the f1-4 with the actual math
\begin{table}[h]
\centering
\caption{Comparison results}
\label{table:nonlin}
\begin{array}{@{}cccccc@{}}
\toprule
& \multicolumn{1}{c}{} & \multicolumn{2}{c}{t = 1} & \multicolumn{2}{c}{t = 2} \\ \cmidrule(l){3-4} \cmidrule(l){5-6}
\beta & Step                  & \|A^{(2)}_{T,S} - X_k\|_2           & \|X_k - X_{k-1} \|_2          & \|A^{(2)}_{T,S} - X_k\|_2           & \|X_k - X_{k-1} \|_2          \\ \midrule
0.9   & k=31                  & 6.1424e-008  & 5.0256e-008 & 8.1170e-016  & 1.3257e-015 \\
& k=32                  & 3.3783e-008  & 2.7641e-008 & 7.0439e-016  & 3.1839e-016\\
\bottomrule
\end{array}
\end{table}

\end{document}


An other possibility where math mode for the table is used and mystrut is defined for the padding of the cell title.

Code

\documentclass[12pt]{article}
\usepackage{latexsym}
\usepackage{siunitx,array}
\usepackage{amsmath, times, amsfonts, mathrsfs, amssymb}
\begin{document}
\newcommand{\mystrut}{\vrule height 15pt depth 10pt width 0pt }
\begin{table}[!ht]
\caption{\small Comparison results}
\small
\centering
\begin{tabular}{>{$} l <{$} *6{>{$} c <{$}}}\hline
\multicolumn{2}{c}{}& \multicolumn{2}{c}{\mystrut $t=1$} & &\multicolumn{2}{c}{$\mystrut t=2$}\\\cline{3-4}\cline{6-7}
\mystrut \beta & \text{Step} &  \|A^{(2)}_{T,S} - X_k\|_2  &  \|X_k - X_{k-1} \|_2   & &  \|A^{(2)}_{T,S} - X_k\|_2  &  \|X_k - X_{k-1} \|_2  \\ \hline
0.9 &  k=31 &  6.1424e-008    &  5.0256e-008   &  & 8.1170e-016 &  1.3257e-015\\
&  k=32 &  3.3783e-008    &  2.7641e-008   &  & 7.0439e-016 & 3.1839e-016 \\
\end{tabular}
\label{table:nonlin}
\end{table}
\end{document}
`