Latex 複数列と複数行

Latex 複数列と複数行

複数行と複数列のテーブルを LaTeX 形式で結合したいのですが、できません。

これが私が LaTeX テンプレートに求めているものです。

ここに画像の説明を入力してください

誰かこれについて助けてくれませんか? ありがとうございます。

答え1

いくつかの提案とコメント:

  • スクリーンショットに表示されている表は非常に「伝統的」です。つまり、窮屈で、魅力がなく、居心地が悪いのです。全体的な印象は刑務所の独房の窓のようです。たくさんの水平バーと垂直バーがあります。その「外観」は、下の最初の表に示されています。

  • 表をよりオープンな「見た目」にすることをぜひ検討してください。これを行うための非常に良い方法は、(a) 垂直線をすべて省略し、(b) より少ないが間隔の広い水平線を使用することです。下の 2 番目の表の結果を確認してください。

  • 2 番目のアプローチのバリエーションとして、tabular*環境の代わりに 環境を使用して、テーブル全体の幅を事前に指定できるようにすることができます。通常、全体の幅は 、つまりテキスト ブロックの幅tabularとして設定されますが、必ずしもそうであるとは限りません。\textwidth

最後に一言: これら 3 つのアプローチのいずれも、テーブルがテキスト ブロック内に収まることを実際に保証するものではありません。この問題は、テーブルに多数の列がある場合に特に発生する可能性があります。これが問題である場合は、これまでに試した内容をレイアウトした新しいクエリを投稿する必要があります。

ここに画像の説明を入力してください

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

関連情報