If you want to do this in tabularx
and with all those rules (I don't like them, they make a table look cluttered, not tidy or legible), I'd suggest using the packages hhline
(gives better spacing than \cline
) and multirow
. I also used array
and \extrarowheight
to get better spacing to the horizontal rules (they are too close in default LaTeX).
\documentclass[journal]{IEEEtran}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{array}
\setlength\extrarowheight{1pt}
\begin{document}
\begin{table}[h]
\caption{Test Table\label{tab:table_x}}
\noindent\begin{tabularx}{\columnwidth} { |
c |
c |
>{\raggedright\arraybackslash}X |
}
\hline
\textbf{A} & \textbf{B} & \textbf{C} \\
\hline
abc & def & ghi \\
\hline
123 & & mno \\
\hhline{|-|~|-|}
jkl & \multirow{-2}{*}[-.5\arrayrulewidth]{456} & 789 \\
\hline
xxx & yyy & zzz \\
\hline
\end{tabularx}
\end{table}
\end{document}
To get exactly the table you show in your image (more or less, that's not exactly the same spacing) don't use tabularx
but a normal tabular
:
\documentclass[journal]{IEEEtran}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{array}
\setlength\extrarowheight{1pt}
\begin{document}
\begin{table}[h]
\centering
\caption{Test Table\label{tab:table_x}}
\begin{tabular}{ | c | c | c | }
\hline
\textbf{A} & \textbf{B} & \textbf{C} \\
\hline
abc & def & ghi \\
\hline
123 & & mno \\
\hhline{|-|~|-|}
jkl & \multirow{-2}{*}[-.5\arrayrulewidth]{456} & 789 \\
\hline
xxx & yyy & zzz \\
\hline
\end{tabular}
\end{table}
\end{document}
What I'd use
Instead of vertical rules (and rules after each line) I'd use the booktabs
rules. If I need to "merge" cells I'd put them in the first column (if applicable) and simply add \addlinespace
after each block. Meaningful data (like numeric data) I'd not omit and merge cells, but repeat:
\documentclass[journal]{IEEEtran}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{table}[h]
\centering
\caption{Test Table\label{tab:table_x}}
\begin{tabularx}{\columnwidth} { c c >{\raggedright\arraybackslash}X }
\toprule
\textbf{A} & \textbf{B} & \textbf{C} \\
\midrule
abc & def & ghi \\
& 456 & mno \\
\addlinespace
jkl & 456 & 789 \\
\addlinespace
xxx & yyy & zzz \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
\multicolumn
and\multirow
?\usepackage{tabularx}
and one package that defines\captionof
(but please note that you don't need\captionof
inside atable
environment,\caption
suffices there).