
下の図のような表を作成したいと思います。
以下のコードは、これまでの私の最善の試みを表しています (表内の単語は実際には何も意味しません)。
\resizebox{9cm}{!} {
\begin{tabular}{l*{2}{c}r}
Model & Linear Regression && MLE \\
\hline
fakedata50 & -1.037 & &4 \\
fakedata100 & -1.038 && 3 \\
fakedata500 & -0.7859 && 2 \\
fakedata5000 &-0.7742 && 2 \\
fakedata10000 &-0.7665&&o \\
fakedata100000 &-0.7206&&j \\
fakedata1000000 &-0.6939&&j \\
\end{tabular} }
しかし、テーブルを中央に配置したいのですが、コマンドが\centering
機能しません。
また、 の値を変更してグラフを拡大しようとすると\resizebox
、フォント サイズも大きくなりますが、これは望ましくありません。表を拡大する量に比例してフォント サイズを大きくする方法はありますか?
最後に、表のタイトルをどのようにタイプセットすればよいでしょうか?
答え1
テーブルを構築する際には、booktabs
パッケージはあなたの親友です。あなたの場合は、siunitx
小数点の位置合わせを支援するパッケージです (もちろん、パッケージは列の位置合わせ以外にも多くのことができます)。
列S
タイプはオプションの引数を取ります。これにより、各列を個別に調整できます。table-format=1.4
この列には1
番号があることを詳細に指定するために使用しました。前に小数点とその後の数字です。数式モードと小数点揃えルーチンから列見出しを「エスケープ」するために、4
列見出しを囲む必要があったことにお気づきでしょう。{Linear Regression}
実際に試していただくための完全なコードはこちらです。
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{lS[table-format=1.4]r}
\toprule
Model & {Linear Regression} & MLE \\
\midrule
fakedata50 & -1.037 & 4 \\
fakedata100 & -1.038 & 3 \\
fakedata500 & -0.7859 & 2 \\
fakedata5000 & -0.7742 & 2 \\
fakedata10000 & -0.7665 & o \\
fakedata100000 & -0.7206 & j \\
fakedata1000000 & -0.6939 & j \\
\bottomrule
\end{tabular}
\end{document}
の「タイトル」を作成したい場合はtable
、 コマンドを使用する必要があります。環境を環境内にcaption
配置するか、パッケージの コマンドを使用する必要があります。tabular
table
captionof
caption
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[!ht]
\centering
\caption{Your caption goes here}
\begin{tabular}{lS[table-format=1.4]r}
\toprule
Model & {Linear Regression} & MLE \\
\midrule
fakedata50 & -1.037 & 4 \\
fakedata100 & -1.038 & 3 \\
fakedata500 & -0.7859 & 2 \\
fakedata5000 & -0.7742 & 2 \\
fakedata10000 & -0.7665 & o \\
fakedata100000 & -0.7206 & j \\
fakedata1000000 & -0.6939 & j \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答え2
標準tabular
環境でも、表のサイズを調整するためのツールが提供されています。最も注目すべきは、長さによってtabcolsep
各列の横の余白が調整されることです。私の例では、表を標準の に収めるために を縮小する必要がありました\textwidth
が、あなたの場合は、その値を増やすことができます。同様に、フォント サイズを に変更しました\small
が、スペースが問題になる場合や、ドキュメント全体で一貫性を維持する場合を除き、その変更を行う必要はありません。
垂直方向のスペースについては、\renewcommand\arraystretch{}
テーブル行間のスペースを拡張するために を使用します。 環境内では、\centering
は問題なく機能します。 環境外で使用する場合は、 を使用します{\centering my table stuff \par}
。 中括弧により、中央揃えの範囲が囲まれた部分だけに制限されます。\par
をアクティブにするには が必要です\centering
。
\documentclass{article}
\usepackage{lipsum}
\usepackage{stackengine}
\def\twostack#1#2{\addstackgap{\stackanchor[0pt]{\strut#1}{\strut#2}}}
\begin{document}
\lipsum[1]
\begin{table}[ht]
\centering
\renewcommand\arraystretch{2}
\tabcolsep 3pt
\caption{Chi-square analysis for data set Total Site 1}
\medskip\small
\begin{tabular}{ccccccc}
\hline
\hline
\textbf{Model} & \textbf{Parameters} & \textbf{Estimates} &
\textbf{\twostack{Chi-square}{statistic}} &
\textbf{P-value} & \textbf{Outcome} & \\
\hline
Geometric Series & $k$ & 0.129202 & 17019.3 & $<$0.001 & Reject\\
\twostack{Broken Stick}{(binned)} & - & - & 1430.72 & $<$0.001 & Reject\\
\twostack{Broken Stick}{(rank abundance)} & - & - & 120085 & $<$0.001 & Reject\\
Logseries & \twostack{$\alpha$}{$x$} & &&&...\\
\hline
\hline
\end{tabular}
\end{table}
\lipsum[2]
\end{document}
答え3
OP が例として挙げた表の冒頭部分はより複雑なので、やり直してみました。小数点の位置合わせが意味のある列には、、、booktabs
およびcaption
パッケージmakecell
を使用しました。このような列 ( 型) では、セルに数値以外の内容が含まれる場合は必ず、それを角括弧で囲む必要があることに注意してください。numprint
n{…}{…}
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe, nomarginpar, noheadfoot]{geometry}
\usepackage{fourier}
\usepackage{heuristica}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup{labelfont = sc, labelsep = period, justification = centering }
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\usepackage[autolanguage, np]{numprint}
\usepackage{stackengine}
\usepackage[english]{babel}
\begin{document}
\begin{table}[!h]
\centering
\caption{Chi-square analysis for data set\enspace Total Site 1}
\begin{tabular}{c >{$}c<{$} n{2}{7}c >{$}n{1}{5}<{$} c}
\toprule\midrule
\thead{Model} & \thead{\textbf{Parameters}} & {\thead{Estimates}} & \thead{Chi-square \\ statistics} & \thead{\textbf{P-value}} & \thead{Outcome} \\
\midrule
\addlinespace
Geometric Series & k & 0.129202 & 17019.3 & < 0.001 & Reject \\
\makecell*{Broken Stick \\ (binned)} & - & {\makecell{--}} & 1430.72 & < 0.001 & Reject \\
\makecell{Broken Stick \\ (rank abundance)} & - & {\makecell{--}} & 120085 & < 0.001 & Reject \\
\multirowcell{2}{Logseries} & α &7.287017 & \multirowcell{2}{20.44702} & {\multirowcell{2}{0.11667}} & Cannot \\%
& x & 0.9999327 & & & reject \\[3pt]
\multirowcell{2}{Lognormal} & M & 6.67146 & \multirowcell{2}{30.8349} & {\multirowcell{2}{< 0.001}} & \multirowcell{2}{Reject} \\
& V & 16.0206 \\
\midrule\bottomrule
\end{tabular}
\end{table}
\end{document}