라텍스 다중 열 및 행

라텍스 다중 열 및 행

LaTeX 형식으로 여러 행과 열 테이블을 결합하고 싶지만 할 수 없습니다.

라텍스 템플릿에서 내가 원하는 것은 다음과 같습니다.

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

누구든지 도와줄 수 있나요? 감사합니다.

답변1

몇 가지 제안 및 의견:

  • 스크린샷에 표시된 테이블은 매우 "전통적"입니다. 즉, 다소 비좁고 매력적이지 않으며 매력적이지 않습니다. 전체적인 인상은 감옥의 창과 같습니다. 수평 및 수직 막대가 많이 있습니다. 그 "모양"은 아래 첫 번째 표에 나와 있습니다.

  • 테이블에 좀 더 개방적인 "모습"을 주는 것에 대해 생각해 보십시오. 이를 수행하는 가장 좋은 방법은 (a) 모든 수직선을 생략하고 (b) 더 적지만 적절한 간격의 수평선을 사용하는 것입니다. 아래 두 번째 표에서 결과를 확인하세요.

  • 두 번째 접근 방식의 변형으로 tabular*환경 대신 환경을 사용하여 tabular테이블의 전체 너비를 미리 지정할 수 있습니다. 반드시 그런 것은 아니지만 일반적으로 전체 너비는 \textwidth텍스트 블록의 너비인 로 설정됩니다.

마지막 설명: 이 세 가지 접근 방식 중 어느 것도 실제로 표가 텍스트 블록 안에 들어가는 것을 보장하지 않습니다. 이 문제는 테이블에 많은 열이 있는 경우 특히 발생할 가능성이 높습니다. 이것이 문제가 발생한 경우 지금까지 시도한 내용을 정리한 새 쿼리를 게시해야 합니다.

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

\documentclass{article}
\usepackage{array,multirow}
\usepackage{booktabs} % for \toprule, \midrule, \cmidrule, and \bottomrule macros

\usepackage{newtxtext} % optional: load Times Roman clone text font

\begin{document}

\begin{table}
\centering

%% A. For the "traditional", i.e., cramped and rather unattractive "look":
\setlength\extrarowheight{2pt} % optional
\begin{tabular}{|l|*{8}{c|}}
\hline
\multirow{2}{*}{\textbf{Mapping Method}} &
\multicolumn{4}{c|}{\textbf{SVM (\%)}} &
\multicolumn{4}{c|}{\textbf{kNN (\%)}} \\
\cline{2-9}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC} 
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC} \\
\hline
\dots & & & & & & & & \\ \hline
\dots & & & & & & & & \\ \hline
\dots & & & & & & & & \\ \hline
\dots & & & & & & & & \\ 
\hline 
\end{tabular}

\bigskip\bigskip
%% B. A much more open "look" (no vertical rules, few but well-spaced horizontal rules)
\setlength\extrarowheight{0pt} % reset to default value
\begin{tabular}{@{}l*{8}{c}@{}}
\toprule
\textbf{Mapping Method} &
\multicolumn{4}{c}{\textbf{SVM (\%)}} &
\multicolumn{4}{c@{}}{\textbf{kNN (\%)}} \\
\cmidrule(lr){2-5} \cmidrule(l){6-9}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC} \\
\midrule
\dots & & & & & & & & \\ 
\dots & & & & & & & & \\ 
\dots & & & & & & & & \\ 
\dots & & & & & & & & \\
\bottomrule
\end{tabular}

\bigskip\bigskip
%% C. Same as "B" , but with overall width set to \textwidth
\setlength{\tabcolsep}{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{8}{c} }
\toprule
\textbf{Mapping Method} &
\multicolumn{4}{c}{\textbf{SVM (\%)}} &
\multicolumn{4}{c}{\textbf{kNN (\%)}} \\
\cmidrule{2-5} \cmidrule{6-9}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC} \\
\midrule
\dots & & & & & & & & \\ 
\dots & & & & & & & & \\ 
\dots & & & & & & & & \\ %\hline
\dots & & & & & & & & \\
\bottomrule
\end{tabular*}
\end{table}
\end{document} 

답변2

@Mico가 원래 제안한 다음 솔루션은 다음과 같습니다.https://tex.stackexchange.com/a/192332/197451, 귀하의 목적에 적합해야 합니다:

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

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{2}
\begin{document}

\emph{Original form: All columns are equally wide.}

\noindent
\begin{tabularx}{\textwidth}{|*{4}{Y|}}
\hline
\multirow{2}{*}{State of Health} 
&\multicolumn{2}{c|}{Fasting Value}&After Eating\\
\cline{2-4}
&Minimum       &Maximum &2 hours after eating\\
\hline
Healthy      &70            &100     &Less than 140\\
\hline
Pre-Diabetes &101           &126     &140 to 200\\
\hline
Diabetes     &More than 126 &N/A     &More than 200\\
\hline
\end{tabularx}

\bigskip
\emph{Modified form: Columns 1 and 4 are 50\% wider than columns 2 and 3.}

\smallskip\noindent
\begin{tabularx}{\textwidth}{|
 >{\hsize=1.2\hsize}Y| 
 >{\hsize=0.8\hsize}Y|
 >{\hsize=0.8\hsize}Y|
 >{\hsize=1.2\hsize}Y|}
\hline
\multirow{2}{*}{State of Health} 
&\multicolumn{2}{c|}{Fasting Value}&After Eating\\
\cline{2-4}
&Minimum       &Maximum &2 hours after eating\\
\hline
Healthy      &70            &100     &Less than 140\\
\hline
Pre-Diabetes &101           &126     &140 to 200\\
\hline
Diabetes     &More than 126 &N/A     &More than 200\\
\hline
\end{tabularx}
\end{document}

관련 정보