居中表格及其标题以及跨越多行的对齐标题

居中表格及其标题以及跨越多行的对齐标题

我想知道如何将表格及其标题居中以及对齐跨多行的标题。以下是 MWE。任何帮助都将不胜感激。谢谢

\documentclass{article}
\usepackage{booktabs}
\usepackage[format=plain,  justification=centering, singlelinecheck=false]{caption}

\begin{document}

\begin{center}
\begin{table}
\captionsetup{justification=justified}
\caption{Logits Implied by Indicator Variables\\ in Model, $logit\left[P\left(Y=1\right)\right]=\alpha+\beta_{1}x+\beta_{2}z$}
\begin{tabular}{lll}
\toprule 
$x$ & $z$ & Logit\tabularnewline
\midrule
0 & 0 & $\alpha$\tabularnewline
1 & 0 & $\alpha+\beta_{1}$\tabularnewline
0 & 1 & $\alpha+\beta_{2}$\tabularnewline
1 & 1 & $\alpha+\beta_{1}+\beta_{2}$\tabularnewline
\bottomrule
\end{tabular}
\end{table}

\end{center}

\vspace{15cm}

\begin{table}
\caption{Logits Implied by Indicator Variables\\ in Model, $logit\left[P\left(Y=1\right)\right]=\alpha+\beta_{1}x+\beta_{2}z$}
\centering{}%
\begin{tabular}{lll}
\toprule 
$x$ & $z$ & Logit\tabularnewline
\midrule
0 & 0 & $\alpha$\tabularnewline
1 & 0 & $\alpha+\beta_{1}$\tabularnewline
0 & 1 & $\alpha+\beta_{2}$\tabularnewline
1 & 1 & $\alpha+\beta_{1}+\beta_{2}$\tabularnewline
\bottomrule
\end{tabular}
\end{table}


\end{document}

答案1

您可以使用以下命令按浮点数设置字幕的宽度width

\documentclass{article}
\usepackage{booktabs}
\usepackage[format=plain,justification=centering,singlelinecheck=false]{caption}

\begin{document}

\begin{table}[t]
  \centering
  \captionsetup{justification=justified,width=0.6\linewidth}
  \caption{Logits Implied by Indicator Variables in Model,
    $logit\left[P\left(Y=1\right)\right]=\alpha+\beta_{1}x+\beta_{2}z$}
  \begin{tabular}{lll}
    \toprule 
    $x$ & $z$ & Logit\tabularnewline \midrule
    0 & 0 & $\alpha$\tabularnewline
    1 & 0 & $\alpha+\beta_{1}$\tabularnewline
    0 & 1 & $\alpha+\beta_{2}$\tabularnewline
    1 & 1 & $\alpha+\beta_{1}+\beta_{2}$\tabularnewline
    \bottomrule
\end{tabular}
\end{table}

\begin{table}[!h]
  \centering
  \captionsetup{position=top}
  \captionbox{Logits Implied by Indicator Variables in Model,
    $logit\left[P\left(Y=1\right)\right]=\alpha+\beta_{1}x+\beta_{2}z$}{%
    \begin{tabular}{lll}
      \toprule 
      $x$ & $z$ & Logit\tabularnewline\midrule
      0 & 0 & $\alpha$\tabularnewline
      1 & 0 & $\alpha+\beta_{1}$\tabularnewline
      0 & 1 & $\alpha+\beta_{2}$\tabularnewline
      1 & 1 & $\alpha+\beta_{1}+\beta_{2}$\tabularnewline
      \bottomrule
    \end{tabular}}
\end{table}

\end{document}

如果标题应该与表格宽度相同,\captionbox则可以使用 提供的命令caption.sty。我建议将标题放在表格旁边。

在此处输入图片描述

答案2

从你的问题和评论我猜你喜欢实现这样的目标(假设你有两列文本):

在此处输入图片描述

对于中心表,您应该使用\centering。使用\begin{center} ... >float> ..\end{center}是错误的,会导致编译错误。对于标题居中,我猜您实际上会寻找选项justification=centerlast

\documentclass[twocolumn]{article}
\usepackage{booktabs}
\usepackage[format=plain,
            justification=centerlast, 
%            singlelinecheck=false
            ]{caption}

\usepackage{lipsum}

\begin{document}
\lipsum[2]
    \begin{table}[hbt]
    \centering
\caption{Logits Implied by Indicator Variables in Model, $logit\left[P\left(Y=1\right)\right]=\alpha+\beta_{1}x+\beta_{2}z$
some more text some more text some more text some more text some more text some more text
}
    \begin{tabular}{lll}
    \toprule
$x$ & $z$ & Logit\tabularnewline
    \midrule
0 & 0 & $\alpha$\tabularnewline
1 & 0 & $\alpha+\beta_{1}$\tabularnewline
0 & 1 & $\alpha+\beta_{2}$\tabularnewline
1 & 1 & $\alpha+\beta_{1}+\beta_{2}$\tabularnewline
    \bottomrule
\end{tabular}
\end{table}

\lipsum[1-2]

    \begin{table}[htb]
    \centering
\caption{Logits Implied by Indicator Variables}
    \begin{tabular}{lll}
    \toprule
$x$ & $z$ & Logit\tabularnewline
    \midrule
0 & 0 & $\alpha$\tabularnewline
1 & 0 & $\alpha+\beta_{1}$\tabularnewline
0 & 1 & $\alpha+\beta_{2}$\tabularnewline
1 & 1 & $\alpha+\beta_{1}+\beta_{2}$\tabularnewline
    \bottomrule
\end{tabular}
\end{table}
    \end{document}

相关内容