2

I wonder how to center table and its catption as well as justifying caption which spans multiple lines. Below is MWE. Any help will be highly appreciated. Thanks

\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}
6
  • Why are you using \\ in the caption, if you want justification? What do you mean by “centering and justifying”?
    – egreg
    Dec 31 '15 at 16:37
  • Caption is too long and table is based on only three small columns.
    – MYaseen208
    Dec 31 '15 at 16:38
  • I saw that. It's not at all clear what you're after. Perhaps setting a wider margin for the caption?
    – egreg
    Dec 31 '15 at 16:41
  • 2
    @MYaseen208 - Does it help if you drop that \\ and set something like \captionsetup{justification=justified, width=0.6\linewidth}? Or setting the caption beside the table? Dec 31 '15 at 16:44
  • 1
    @egreg I think he wants the caption centered, but justified (i.e. it doesn't exceed the table width).
    – Alenanno
    Dec 31 '15 at 16:46
2

You can set the width of captions on a per float basis with the width key:

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

If the caption should have the same width as the table, you can use the \captionbox command also provided by caption.sty. I would recommend the caption beside table.

enter image description here

1

From your question and its comments I guess that you like to achieve something like this (assuming, that you haw two column text):

enter image description here

For center table you should use \centering. Use \begin{center} ... >float> ..\end{center} is wrong and gives error in compilation. For centering of caption, I guess that you actually look for option 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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.