내가 사용할 것

내가 사용할 것

표에서 두 개의 셀을 하나의 셀로 병합하려면 어떻게 해야 합니까?

예를 들어, 다음과 같이 "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. 나는 또한 수평 규칙에 대한 더 나은 간격을 얻기 위해 array및를 사용했습니다 \extrarowheight(기본 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}

여기에 이미지 설명을 입력하세요

이미지에 표시되는 테이블을 정확하게 얻으려면(다소, 정확히 동일한 간격은 아님) 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

귀하의 코드에는 몇 가지 오류(패키지 하나가 누락됨)가 있으므로 실제로 재현할 수 없습니다. 내 근사치를 살펴보십시오.

\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}

여기에 이미지 설명을 입력하세요

관련 정보