동일한 열이 있는 테이블

동일한 열이 있는 테이블

4행, 3열, 2-3열에 부분 수평선이 있는 테이블이 필요합니다. 나는 시도했다:

\documentclass{article}

\begin{document}

\begin{table}
{
 \begin{center}
\begin{tabular}{|c|c|c|}
\hline
Col 1 & \multicolumn{2}{|c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabular}
\end{center}
}
\end{table}     

\end{document}

결과는 다음과 같습니다.

열 2와 3의 너비는 동일하지 않습니다. 어떻게 해결할 수 있나요?

답변1

을 사용하여 생성된 확장된 셀의 내용 너비가 \multicolumn개별 셀의 콘텐츠 너비보다 큰 경우 경험한 것처럼 마지막 확장된 열에 추가 공간이 추가되며 이 예에서는 더욱 명확하게 보여줍니다.

\documentclass{article}

\begin{document}

\noindent\begin{tabular}{|c|c|c|c|}
\hline
A & \multicolumn{3}{c|}{Some text just for the example} \\
\hline
B & C & D & E \\
\hline
\end{tabular}

\end{document}

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

두 가지 옵션: 중앙 열로 변경할 수 있습니다 p{...}(두 가지 옵션은 패키지 유무에 관계없이 동일한 접근 방식을 보여줍니다 tabularx).

\documentclass{article}
\usepackage{tabularx}

\newcolumntype{C}{>{\centering\arraybackslash}p{1.5cm}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|c|c|c|}
\hline
Col 1 & \multicolumn{2}{c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabular}
\end{table}     

\begin{table}
\centering
\begin{tabular}{|C|C|C|}
\hline
Col 1 & \multicolumn{2}{c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabular}
\end{table}     

\begin{table}
\centering
\begin{tabularx}{6cm}{|Y|Y|Y|}
\hline
Col 1 & \multicolumn{2}{c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabularx}
\end{table}     

\end{document}

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

질문과 관련이 없습니다. 플로트 내부는 환경 \centering이 아니라 사용하는 것이 더 좋습니다 center. 나중에는 대부분의 경우 바람직하지 않은 추가 수직 공간을 추가합니다.

관련 정보