
表内の 2 つのセルを 1 つのセルに結合するにはどうすればよいでしょうか?
たとえば、「456」のセルを次のように結合します。
\documentclass[journal]{IEEEtran}
\begin{document}
\begin{table}[h]
\captionof{table}{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 & 456 & mno \\
\hline
jkl & 456 & 789 \\
\hline
xxx & yyy & zzz \\
\hline
\end{tabularx}
\end{table}
\end{document}
現在のテーブル:
答え1
tabularx
これを と ですべてのルールを使って実行したい場合(私はそれらのルールが好きではありません。それらのルールがあると表が雑然として、整然とせず読みにくく見えるからです)、パッケージhhline
( よりも間隔が広くなります\cline
) とを使用することをお勧めします。また、水平方向のルールとの間隔を広くするためにとmultirow
を使用しました(デフォルトの LaTeX ではルールが近すぎます)。array
\extrarowheight
\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}
画像に表示されているテーブルを正確に取得するには (多かれ少なかれ、まったく同じ間隔ではありません)、tabularx
通常の ではなく を使用します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}
私が使うもの
垂直線 (および各行の後の線) の代わりに、私はbooktabs
線を使用します。セルを「結合」する必要がある場合は、最初の列 (該当する場合) にセルを配置し、各ブロックの後に追加します\addlinespace
。意味のあるデータ (数値データなど) は、セルを省略して結合するのではなく、繰り返します。
\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}
答え2
コードにはいくつかのエラーがあるため (パッケージが 1 つ欠落している)、実際には再現できません。私の概算を見てみましょう:
\documentclass[journal]{IEEEtran}
\usepackage{multirow} % <-- added package
\usepackage{tabularx}
\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 & \multirow{2}{*}{456} & mno \\ % <-- merged cell
\cline{1-1}\cline{3-3} % <-- added rule
jkl & & 789 \\ % <-- merged cell
\hline
xxx & yyy & zzz \\
\hline
\end{tabularx}
\end{table}
\end{document}
答え3
新しいパッケージ tabularray を使用すると、非常に簡単に実行できます。
\documentclass[journal]{IEEEtran}
\usepackage{tabularray}
\begin{document}
\begin{table}[h]
\caption{Test Table}
\label{tab:table_x}
\centering
\begin{tblr}{
colspec = {QQQ},
hlines,
vlines,
columns={c},
rows={m},
cell{3}{2} = {r=2,c=1}{c},
row{1}={font=\bfseries},
}
A & B & C \\
abc & def & ghi \\
123 & 456 & mno \\
jkl & 456 & 789 \\
xxx & yyy & zzz \\
\end{tblr}
\end{table}
\end{document}