
\documentclass{article}
\usepackage{}
\usepackage{makecell, multirow, tabularx}
\begin{document}
\begin{table}[h!]
\setlength\extrarowheight{2pt} % for a ever so slightly more open "look"
\begin{tabularx}{\textwidth}{X |c |c |c |c |}
\cline{2-5}
& Mean & N & Std. Deviation & Std. Error Mean \\
\hline
Testing123 Testin123 Testing123 Testin123 & 23\% & 10\% & 279\% & 233\% \\
\hline
\end{tabularx}
\caption{Testing123 Testin123Testing123 Testin123}
\end{table}
複数列で追加しました
\begin{table}[h!]
\setlength\extrarowheight{2pt} % for a ever so slightly more open "look"
\begin{tabularx}{\textwidth}{X |c |c |c |c |}
\cline{2-5}
& Mean & N & Std. Deviation & Std. Error Mean \\
\hline
\multicolumn{1}{|c|}{Testing123 Testin123 Testing123 Testin123} & 23\% & 10\% & 279\% & 233\% \\
\hline
\end{tabularx}
\caption{Testing123 Testin123Testing123 Testin123}
\end{table}
結果:
そして、「Testing123 Testin123 Testing123 Testin123」を2行にしたいと思いました。
答え1
@Jenniferのコードを見ると、最初のヘッダーセル(Mean)の左の縦線が次の行の縦線と揃っていないことがわかります。これは、縦棒( )が正しく配置されていないためです。最初の列の右側の と|
を設定する必要があります。|
X
\multicolumn
取り除く\multicolumn
2番目のヘッダーセルからのコマンド。最初の行は次のようになります。
\multicolumn{1}{X|}{} & Mean & N & Std. Deviation & Std. Error Mean \\
完全な MWE は次のとおりです。
\documentclass{article}
\usepackage{tabularx, caption} % Load package caption for better captions
\usepackage{booktabs, ragged2e} % Use ragged2e to improve ragged text
\setlength\extrarowheight{1pt} % Both line necessary for decent spacing
\renewcommand{\arraystretch}{1.2}
\begin{document}
\begin{table}[!ht]
\caption{Testing123 Testin123Testing123 Testin123% % Caption above table
\label{tab:test123}% % Label inside caption
}
\begin{tabularx}{\textwidth}{|>{\RaggedRight\arraybackslash}X|c |c |c |c |}
\cline{2-5}
\multicolumn{1}{X|}{} % Right vertical rules in first header cell
& Mean % Remove `multicolumn` from second header cell
& N & Std. Deviation
& Std. Error Mean \\
\hline
Testing123 Testin123 Testing123 Testin123 & 23\% & 10\% & 279\% & 233\% \\
\hline
\end{tabularx}
\end{table}
ただし、表形式を別の方法でタイプセットすることをお勧めします。
- 使用ブックタブより良いルールのために
- 縦罫線をすべて取り除きます(ブックタブマニュアル)
@{}
左右のベアリングを取り外すために使用します- 新しい列タイプを定義して、4つの列を均等な幅で設定します。
- 図の列を右揃えにする
- パーセント記号をヘッダーに移動する
表の前文は次のとおりです。
\begin{tabularx}{\textwidth}{@{}M*{4}{N}@{}}
つまり、
@{}
= 1列目の左側のサイドベアリング、つまり最初の列の先頭にある小さなスペースを削除します。M
= 型の列を 1 つ設定します(ドキュメントのプリアンブルでM
コマンドを使用して定義しました)。\newcolumntype
*{4}{N}
N
= は、(ドキュメントのプリアンブルでコマンドを使用して定義した)型の列を 4 つ作成することを意味します\newcolumntype
。この MWE で 4 と記述するのと同じですNNNN
が、通常はショートカットです。@{}
= 最後の列については、上記の項目1と同じです。サイドベアリングを取り外します。右5列目のつまり最後の列の末尾に表示される小さなスペース。
今ではより理解しやすくなったと思います。
\documentclass{article}
\usepackage{tabularx, caption} % Load package caption for decent foramtting and spacing
\usepackage{booktabs, ragged2e} % Use booktabs rules and get rid of vertical rules,
% ragged2e to improved ragged right and left text
\setlength\extrarowheight{1pt} % Both line necessary for decent spacing, unless you are using booktabs rules.
\renewcommand{\arraystretch}{1.2}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash\hsize=2\hsize\linewidth=\hsize}X}
\newcolumntype{W}{>{\RaggedLeft\arraybackslash\hsize=0.75\hsize\linewidth=\hsize}X}
\begin{document}
\begin{table}[!ht]
\caption{Testing123 Testin123Testing123 Testin123%
\label{tab:test123}%
}
\begin{tabularx}{\textwidth}{@{}Y*{4}{W}@{}}
\toprule
& \small Mean (\%)
& \small N (\%)& \small Std. Deviation~(\%)
& \small Std. Error Mean (\%)\\
\midrule
Testing123 Testin123 Testing123 Testin123 & 23 & 10 & 279 & 233 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答え2
ヘッダー行に複数列を2回追加しました。これがあなたが探しているものであることを願っています
\documentclass{article}
\usepackage{}
\usepackage{makecell, multirow, tabularx}
\begin{document}
\begin{table}[h!]
\setlength\extrarowheight{2pt} % for a ever so slightly more open "look"
\begin{tabularx}{\textwidth}{|X|c |c |c |c |}
\cline{2-5}
\multicolumn{1}{l}{}
& \multicolumn{1}{|l|}{Mean} & N & Std. Deviation & Std. Error Mean \\
\hline
Testing123 Testin123 Testing123 Testin123 & 23\% & 10\% & 279\% & 233\% \\
\hline
\end{tabularx}
\caption{Testing123 Testin123Testing123 Testin123}
\end{table}
\end{document}