How can I solve this problem with latex table?

I want to make a table like this:

So I tried with this Latex code:

\begin{table}[h!]
\begin{center}
\begin{tabular}{|l|c|c|}
\hline \multirow{2}{3cm}{Filter Type} &
\multicolumn{2}{|c|}{Ideal impulse response $h_D(n)$} \\
\cline{2-2} & $h_D(n), \; n\neq 0$ & $h_D(0)$ \\ \hline
\end{tabular}
\end{center}
\end{table}


But I get this table instead:

I don't know how to fix my problem, so I appreciate if someone could help me.

• Welcome to TeX.SE! Write \cline{2-3} instead of \cline{2-2}. – CarLaTeX Dec 8 '18 at 10:43
• Wow, I didn't know it was so simple, maybe I should get more information about de \cline command. Thank you so much! – Josemi Dec 8 '18 at 10:45
• Also replace both the c columns with >{\centering\arraybackslash}p{2.5cm} columns in order to have space too (length 2.5 cm is just a guess... test it) – koleygr Dec 8 '18 at 10:47
• You're welcome! The syntax is \cline{StartColumn-EndColumn}. – CarLaTeX Dec 8 '18 at 10:55
• Welcome to TeX - LaTeX! In general it is better post a complete minimal document that we can compile, rather than a code snippet, cf. minimal working example (MWE) – Andrew Swann Dec 8 '18 at 10:59

A minimal modification to your code to get the vertical placing of "Filter Type" and the requested rule is:

\documentclass{article}

\begin{document}
\begin{table}[h!]
\begin{center}
\begin{tabular}{|l|c|c|}
\hline Filter Type
& \multicolumn{2}{|c|}{Ideal impulse response $h_D(n)$} \\
\cline{2-3} & $h_D(n), \; n\neq 0$ & $h_D(0)$ \\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}


However, you should consider whether you need all these vertical rules. I guess this is just heading material for a table, in which case I would suggest:

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{center}
\begin{tabular}{l*{2}{c}}
\toprule
Filter Type
& \multicolumn{2}{c}{Ideal impulse response $h_D(n)$} \\
& $n\neq 0$ & $n=0$ \\
\midrule
X&$2$&$-1$\\
Y&$3$&$2$ \\
\bottomrule
\end{tabular}
\end{center}

\end{document}


Note that a table environment is not necessary, particularly if you want placement at a particular point on the page. If you need a caption, then the \captionof command from the caption package can be used.

See the documentation of the booktabs package for more advice on good style for tables.