# Create complex table with LaTeX

I am very new to LaTeX, and I am trying to create a table. The table should look like this one:

I created this code:

\begin{table}[h!]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{lll}
Path       & \multicolumn{2}{l}{Alice}  \\
Type       & \multicolumn{2}{l}{Client} \\
Parameters &              &
\end{tabular}
\end{table}


But I am stuck on how to add the parameters. It also doesn't show the table lines. How can I do this?

• don't use [h!] it generally produces a warning that it is being changed to [ht] but [htp] is better. – David Carlisle Jan 10 '17 at 17:16
• Welcome to TeX.SE! Your table is not really complex ... :). To become more familiar to them, start to read some basic documentation about LaTeX tables. For example en.wikibooks.org/wiki/LaTeX/Tables. In a future, please provide complete small document starting with \documentclass{...} and ending with \end{document}. With this you will help people who would be willing to help you. – Zarko Jan 10 '17 at 17:16

Dan's answer is very good and teaches how to build such a table from scratch. However, if you have several tables following the same patterns it might be better to have a higher level syntax for them.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\parametertable}{mmm}
{
\seq_set_split:Nnn \l_ella_parametertable_parameters_seq { \\ } { #3 }
\begin{tabular}{|l|p{1in}|p{1in}|}
\hline
Name & \multicolumn{2}{l|}{#1} \\
\hline
Type & \multicolumn{2}{l|}{#2} \\
\hline
Parameters &
\seq_use:Nn \l_ella_parametertable_parameters_seq { \\ \cline{2-3} & }
\\
\hline
\end{tabular}
}
\ExplSyntaxOff

\begin{document}

\parametertable{Alice}{Client}{
Param1 & Value \\
Param2 & Value \\
Param3 & Value
}

\end{document}


The advantage to such an approach will be evident when you'll decide that, after all, those rules are annoying and you'll want to switch to booktabs. Just modifying the main command in a few details, all your similar tables will change format.

\documentclass{article}
\usepackage{xparse}
\usepackage{booktabs}

\ExplSyntaxOn
\NewDocumentCommand{\parametertable}{mmm}
{
\seq_set_split:Nnn \l_ella_parametertable_parameters_seq { \\ } { #3 }
\begin{tabular}{lp{1in}p{1in}}
\toprule
Name & \multicolumn{2}{l}{#1} \\
\midrule
Type & \multicolumn{2}{l}{#2} \\
\midrule
Parameters &
\seq_use:Nn \l_ella_parametertable_parameters_seq { \\ & }
\\
\bottomrule
\end{tabular}
}
\ExplSyntaxOff

\begin{document}

\parametertable{Alice}{Client}{
Param1 & Value \\
Param2 & Value \\
Param3 & Value
}

\end{document}


Note that the document code has not changed in any way.

Using \cline you could do something along the lines of this...

Code:

\documentclass{amsart}
\begin{document}
\begin{tabular}{|p{1in}|p{1in}|p{1in}|}
\hline
Name&\multicolumn{2}{|c|}{Alice}\\\hline
Type&\multicolumn{2}{|c|}{Client}\\\hline
Parameters&Param1&Value\\\cline{2-3}
&Param2&Value\\\cline{2-3}
&Param3&Value\\\hline
\end{tabular}
\end{document}


Yields:

An alternative of a completely different kind, in addition to Dan's great answer.

There are websites that let you create Latex tables online in a WYSIWYG way, such as http://www.tablesgenerator.com/. They are a good way to get things done at first while you learn, and at the same time you can inspect the code they produce and learn how to do it yourself.

In your case, you can produce with minimal effort the following result.

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|l|l|}
\hline
Name       & \multicolumn{2}{l|}{Alice}  \\ \hline
Type       & \multicolumn{2}{l|}{Client} \\ \hline
Parameters & Param1        & Value       \\ \cline{2-3}
& Param2        & Value       \\ \cline{2-3}
& Param2        & Value       \\ \hline
\end{tabular}
\end{table}


To add a little bit of explanation to Dan's answer above, the vertical bars in the \begin{tabular} statement provide the lines between columns, and the \hline and \cline commands provide the lines between rows. In particular, \cline{2-3} restricts the horizontal line to just columns 2 and 3.

If you're coming from some other kind of markup (such as html) you might expect tables to include this sort of decoration by default, but that's not the case in LaTeX. Most LaTeX users see this as a good thing, as it allows for greater flexibility, but it does make the learning curve steeper.

My another example.

\documentclass[a4paper,12pt]{article}
\usepackage{multirow}
\newcommand{\mc}[2]{\multicolumn{#1}{c}{#2}}

\begin{document}

\begin{table}[]
\centering
\caption{My table}
\begin{tabular}{|l|l|l|l|l|}
\hline
Name & \mc{1}{Alice}  &\\ \hline
Type & \mc{1}{Client} &\\ \hline
\multirow{3}{*}{Parameters} & Param1 & Value \\ \cline{2-3}
& Param2 & Value \\ \cline{2-3}
& Param3 & Value \\ \hline
\end{tabular}
\end{table}

\end{document}