LaTeX でタイトル付きの次の表を作成するにはどうすればよいですか?

LaTeX でタイトル付きの次の表を作成するにはどうすればよいですか?

下の図のような表を作成したいと思います。

望んだ

以下のコードは、これまでの私の最善の試みを表しています (表内の単語は実際には何も意味しません)。

\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配置するか、パッケージの コマンドを使用する必要があります。tabulartablecaptionofcaption

キャプション付きスクリーンショット

% 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を使用しました。このような列 ( 型) では、セルに数値以外の内容が含まれる場合は必ず、それを角括弧で囲む必要があることに注意してください。numprintn{…}{…}

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

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

関連情報