32

Here is a simple table.

I want to merge 4 cells. I want to combine the three "this" cells area in this table.
I thought I have to use multirow and multicolum at same time.
However, I could not find how to use it.

If possible, could you post the modified LaTeX source code?

picture of table

My LaTeX code:

\documentclass{article}
\usepackage{multirow}% http://ctan.org/pkg/multirow
\usepackage{hhline}% http://ctan.org/pkg/hhline
\begin{document}

\begin{table}[ph]
\begin{center}
\begin{tabular}{c|c|c|c|c}
\hline
\multirow{2}{*}{Raaa (k)} & \multicolumn{4}{c}{C ()} \\
\hhline{~----}
 & 3.3 & 2.5 & 1 & 0.5 \\
\hline
\multirow{2}{*}{Raaa (k)} & \multirow{2}{*}{this} & this & 0.5 & 0.6\\
\hhline{~~~--}            &                       & this & 0.7 & 1.2 \\
\hline
\end{tabular}
\caption{R, C ripple size}
\label{T:peak}
\end{center}
\end{table}
\end{document}
  • 2
    Welcome to TeX.sx! Next time you ask a question, please add a full minimal working example (MWE). As you just posted the table, Werner had to find out that you're using the packages multirow and hhline in order to solve your problem. That's just unnecessary work. Also, it'd be nice if you added a picture to this question, now as you have some reputation points and the new user restrictions have been removed from your account. – doncherry Nov 17 '11 at 13:42
  • @doncherry He's not gonna do it, the question is popular and one of the top google hits for the request. I did my best at editing, would you mind reviewing ? – Nikana Reklawyks Feb 21 '17 at 15:24
52

Both rows should contain a \multicolumn{2}{c|}{...}, and the first row should contain a nested \multirow{2}{*}{...}:

enter image description here

\documentclass{article} 
\usepackage{multirow}% http://ctan.org/pkg/multirow
\usepackage{hhline}% http://ctan.org/pkg/hhline
\begin{document}
\begin{table}[ph]
  \centering
  \begin{tabular}{c|c|c|c|c}
    \hline
    \multirow{2}{*}{Raaa (k)} & \multicolumn{4}{c}{C ()} \\
    \hhline{~----}
    & 3.3 & 2.5 & 1 & 0.5 \\
    \hline
    \multirow{2}{*}{Raaa (k)} & \multicolumn{2}{c|}{\multirow{2}{*}{this}} & 0.5 & 0.6\\
    \hhline{~~~--}            & \multicolumn{2}{c|}{}                      & 0.7 & 1.2 \\
    \hline
  \end{tabular}
  \caption{R, C ripple size}
  \label{T:peak}
\end{table}
\end{document}

Since \multicolumn overrides any of the set column alignments (including the vertical rules), you have to respecify everything. Hence the use of c| to center the contents and end it with a vertical rule.

Also note how I used \centering instead of the center environment (\begin{center} ... \end{center}). This allows for better vertical spacing around elements in your document. Consider reading the following post: Should I use center or centering for figures?

22

Vertical lines burn my eyes. Tables almost always look better without them. Here's a version that uses booktabs for nice horizontal lines.

\documentclass{article} 
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}

\begin{table}[ht]
\centering
\begin{tabular}{ccccc}
  \toprule
    \multirow{2}{*}{Raaa (k)} & \multicolumn{4}{c}{C ()} \\
    \cmidrule{2-5} & 3.3 & 2.5 & 1 & 0.5 \\
  \midrule
    \multirow{2}{*}{Raaa (k)} & \multicolumn{2}{c}{\multirow{2}{*}{this}} & 0.5 & 0.6 \\
    \cmidrule{4-5}            & \multicolumn{2}{c}{}                      & 0.7 & 1.2 \\
  \bottomrule
\end{tabular}
\caption{R, C ripple size}
\end{table}

\end{document}

Which gives you this:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.