5

I decided to write my Masters using LaTeX a week ago. I start from zero. I learn everything thanks to you and this forum. Please be indulgent and do not laugh at my code :-) So, I am trying to create a table with 3 subtables. My problems are:

  1. The last column of my first subtable is too long. I think this is due to my very long sentence in my last line. I cannot find a way to change its width.
  2. I do not know what to use between tabular, tabularx, tabular* to change this width. I tried different things with tabularx and sub caption but nothing worked.
  3. I would like to have the same width for the 3 subtables.
  4. I would like to put the a), b), c) on the left and aligned with "Fixed effects" instead of above each subtable and centered.

Here is my code:

\usepackage{graphicx}
\usepackage[french,english]{babel}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{subcaption}
\begin{document}
\renewcommand{\thetable}{\arabic{table}}
\begin{table}[]
\caption{A first very long sentence. a) Name of my first subtable. b) Name of my second subtable. c) Name of my third subtable.}
\scriptsize
\centering
\begin{subtable}{0.9\textwidth}
\centering
\subcaption{}
\begin{tabular}{l c c c c}
\cline{1-5}
Fixed effects & \multicolumn{1}{c}{Estimate $\pm$ SE} & \multicolumn{2}{c}{Z} & \multicolumn{1}{r}{P} \\
\cline{1-5}
(Intercept) & \multicolumn{1}{c}{-0.27 $\pm$ 0.13} & \multicolumn{2}{c}{-2.10} & \multicolumn{1}{r}{0.036} \\
Trial & \multicolumn{1}{c}{0.00 $\pm$ 0.05} & \multicolumn{2}{c}{0.04} & \multicolumn{1}{r}{0.965} \\
\cline{1-5}
Random effects & \multicolumn{1}{c}{Variance $\pm$ SD} & \multicolumn{1}{c}{LRT} & \multicolumn{1}{c}{d.f.} & \multicolumn{1}{r}{P} \\
\cline{1-5}
Bird (intercept) & \multicolumn{1}{c}{0.55 $\pm$ 0.74} & \multicolumn{1}{r}{159} & \multicolumn{1}{c}{1} & \multicolumn{1}{r}{< 0.001} \\
Bird (slope with trial) & \multicolumn{1}{c}{0.02 $\pm$ 0.16} & \multicolumn{1}{r}{1.40} & \multicolumn{1}{c}{1} & \multicolumn{1}{r}{0.237} \\
Flock (intercept) & \multicolumn{1}{c}{0.00 $\pm$ 0.00} & \multicolumn{1}{r}{0} & \multicolumn{1}{c}{1} & \multicolumn{1}{r}{1} \\
\cline{1-5}
\multicolumn{5}{l}{\multirow{2}{\linewidth}{N = 454. The response variable is the proportion of scrounged patches, expressed as a 2-column matrix composed of the number of scrounged patches and number of produced patches.}} \\
\multicolumn{5}{l}{} \\
\end{tabular}
\label{tbl:sub-table-a}
\end{subtable}      
\begin{subtable}{0.9\textwidth}
\centering
\subcaption{}
\begin{tabular}{l c c c c}
\cline{1-5}
Fixed effects & \multicolumn{1}{c}{Estimate $\pm$ SE} & \multicolumn{2}{c}{Z} & \multicolumn{1}{r}{P} \\ 
\cline{1-5} 
(Intercept) & \multicolumn{1}{c}{-0.26 $\pm$ 0.19} & \multicolumn{2}{c}{-1.39} & \multicolumn{1}{r}{0.166} \\
Trial & \multicolumn{1}{c}{0.04 $\pm$ 0.09} & \multicolumn{2}{c}{0.44} & \multicolumn{1}{r}{0.659} \\
\cline{1-5} 
Random effects & \multicolumn{1}{c}{Variance $\pm$ SD} & \multicolumn{1}{c}{LRT} & \multicolumn{1}{c}{d.f.} & \multicolumn{1}{r}{P} \\
\cline{1-5} 
Bird (intercept) & \multicolumn{1}{c}{0.60 $\pm$ 0.77} & \multicolumn{1}{r}{81.2} & \multicolumn{1}{c}{1} & \multicolumn{1}{r}{< 0.001}     \\
Bird (slope with trial) & \multicolumn{1}{c}{0.05 $\pm$ 0.22} & \multicolumn{1}{r}{1.68} & \multicolumn{1}{c}{1} & \multicolumn{1}{r}{0.194} \\
Flock (intercept) & \multicolumn{1}{c}{0.00 $\pm$ 0.00} & \multicolumn{1}{r}{0} & \multicolumn{1}{c}{1} & \multicolumn{1}{r}{1} \\ 
\cline{1-5}  
\multicolumn{5}{l}{N = 234.} \\
\end{tabular}
\label{tbl:sub-table-b}
\end{subtable}
\begin{subtable}{0.9\textwidth}
\centering
\subcaption{}
\begin{tabular}{l c c c c}
\cline{1-5}
Fixed effects & \multicolumn{1}{c}{Estimate $\pm$ SE} & \multicolumn{2}{c}{Z} & \multicolumn{1}{r}{P} \\ 
\cline{1-5} 
(Intercept) & \multicolumn{1}{c}{-0.27 $\pm$ 0.17} & \multicolumn{2}{c}{-1.57} & \multicolumn{1}{r}{0.117} \\
Trial & \multicolumn{1}{c}{-0.03 $\pm$ 0.07} & \multicolumn{2}{c}{-0.42} & \multicolumn{1}{r}{0.674} \\ 
\cline{1-5} 
Random effects & \multicolumn{1}{c}{Variance $\pm$ SD} & \multicolumn{1}{c}{LRT} & \multicolumn{1}{c}{d.f.} & \multicolumn{1}{r}{P} \\ 
\cline{1-5}
Bird (intercept) & \multicolumn{1}{c}{0.50 $\pm$ 0.71} & \multicolumn{1}{r}{77.5} & \multicolumn{1}{c}{1} & \multicolumn{1}{r}{< 0.001} \\
Bird (slope with trial) & \multicolumn{1}{c}{0.01 $\pm$ 0.10} & \multicolumn{1}{r}{0.17} & \multicolumn{1}{c}{1} & \multicolumn{1}{r}{0.682} \\
Flock (intercept) & \multicolumn{1}{c}{0.00 $\pm$ 0.00} & \multicolumn{1}{r}{0} & \multicolumn{1}{c}{1} & \multicolumn{1}{r}{1} \\ 
\cline{1-5}  
\multicolumn{5}{l}{N = 220.} \\ 
\end{tabular}
\label{tbl:sub-table-c}
\end{subtable}
\label{tab:scrounging}
\end{table}
\end{document}

enter image description here Thousand thanks for all your help! :-D

  • Welcome to TeX.SE! You wrote "...I decided to write my Masters using LaTeX..." -- excellent decision!! :-) – Mico Nov 16 '16 at 21:35
  • Thank you Mico! I find this community extremely active. It is very inspiring and it validates my decision to learn LaTeX! – user118919 Nov 16 '16 at 21:50
2

Some suggestions, made in no particular order:

  • Use the line-drawing macros of the booktabs package -- \toprule, \midrule, etc -- instead of \hline and \cline to get well-spaced horizontal lines.

  • Using \scriptsize is bound to make readers squint, and possible want to skip ahead to other material. Don't go below \footnotesize if you expect your readers to spend some time taking in the tabular material.

  • Use a common width of ca 0.7\textwidth for each of the three subtable environments, and make sure that all three tabular environments have the same width; this may be achieved by using a p{\textwidth} directive for the final row in each tabular environment.

  • Save yourself a lot of typing (all those \multicolumn directives must be getting old...) in the body of a tabular environment by setting up "smart", specifically, automatic math-mode columns for the 4 data columns. In the preamble below, look for how the C and R column types are defined.

  • To left-justify the captions of the subtable environments, run an instruction such as

    \captionsetup[subtable]{singlelinecheck=false,justification=raggedright}
    

    Do use the same font size for the captions as you do for the embedded tabular environments.

  • Unless you like to go on (code) scavenger hunts, do keep the \caption and associated \label directives together.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french,english]{babel}
\usepackage{amsmath,multirow}
\usepackage{booktabs,array,subcaption}
\newcolumntype{C}{>{$}c<{$}}
\newcolumntype{R}{>{$}r<{$}}
\begin{document}
\renewcommand{\thetable}{\arabic{table}}
\begin{table}
\footnotesize
\captionsetup[subtable]{size=footnotesize,
                        singlelinecheck=false,
                        justification=raggedright}
\caption{A first very long sentence. a) Name of my first subtable. 
b) Name of my second subtable. 
c) Name of my third subtable.} 
\label{tab:scrounging}

\centering % a single \centering instruction suffices

\begin{subtable}{0.7\textwidth}
\caption{} \label{tbl:sub-table-a}
\begin{tabular}{@{}lCRCR@{}}
\toprule
Fixed effects & \text{Estimate} \pm \text{SE} & \multicolumn{2}{C}{Z} & P \\
\midrule
(Intercept) & -0.27 \pm 0.13 & \multicolumn{2}{C}{-2.10} & 0.036 \\
Trial       & \phantom{-}0.00 \pm 0.05 & \multicolumn{2}{C}{\phantom{-}0.04} & 0.965 \\
\midrule
Random effects & \text{Variance} \pm \text{SD} & \text{LRT} & \text{d.f.} & P \\
\midrule
Bird (intercept) & 0.55 \pm 0.74 & 159 & 1 & < 0.001 \\
Bird (slope with trial) & 0.02 \pm 0.16 & 1.40 & 1 & 0.237 \\
Flock (intercept) & 0.00 \pm 0.00 & 0 & 1 & 1 \\
\midrule
\multicolumn{5}{@{}p{\textwidth}@{}}{$N = 454$. The response variable is 
the proportion of scrounged patches, expressed as a 2-column matrix 
composed of the number of scrounged patches and number of produced patches.} \\
\end{tabular}
\end{subtable}   

\bigskip % insert some space between the subtables
\begin{subtable}{0.7\textwidth}
\subcaption{} \label{tbl:sub-table-b}
\begin{tabular}{@{}lCRCR@{}}
\toprule
Fixed effects & \text{Estimate} \pm \text{SE} & \multicolumn{2}{C}{Z} & P \\ 
\midrule 
(Intercept) & -0.26 \pm 0.19 & \multicolumn{2}{C}{-1.39} & 0.166 \\
Trial & \phantom{-}0.04 \pm 0.09 & \multicolumn{2}{C}{\phantom{-}0.44} & 0.659 \\
\midrule 
Random effects & \text{Variance} \pm \text{SD} & \text{LRT} & \text{d.f.} & P \\
\midrule 
Bird (intercept) & 0.60 \pm 0.77 & 81.2 & 1 & < 0.001 \\
Bird (slope with trial) & 0.05 \pm 0.22 & 1.68 & 1 & 0.194 \\
Flock (intercept) & 0.00 \pm 0.00 & 0 & 1 & 1 \\ 
\midrule  
\multicolumn{5}{@{}p{\textwidth}@{}}{$N = 234$.} \\
\end{tabular}
\end{subtable}

\bigskip
\begin{subtable}{0.7\textwidth}
\subcaption{} \label{tbl:sub-table-c}
\begin{tabular}{@{}lCRCR@{}}
\toprule
Fixed effects & \text{Estimate}\pm\text{SE} & \multicolumn{2}{C}{Z} & P \\ 
\midrule 
(Intercept) & -0.27 \pm 0.17 & \multicolumn{2}{C}{-1.57} & 0.117 \\
Trial & -0.03 \pm 0.07 & \multicolumn{2}{C}{-0.42} & 0.674 \\ 
\midrule 
Random effects & \text{Variance}\pm\text{SD} & \text{LRT} & \text{d.f.} & P \\ 
\midrule
Bird (intercept) & 0.50 \pm 0.71 & 77.5 & 1 & < 0.001 \\
Bird (slope with trial) & 0.01 \pm 0.10 & 0.17 & 1 & 0.682 \\
Flock (intercept) & 0.00 \pm 0.00 & 0 & 1 & 1 \\ 
\midrule  
\multicolumn{5}{@{}p{\textwidth}@{}}{$N = 220$.} \\ 
\end{tabular}
\end{subtable}
\end{table}
\end{document}


Addendum to address the first of the OP's follow-up questions: If you want to make the "gaps" between the columns equally wide, I suggest you use tabular* environments, as shown in the following code. The somewhat unwieldy-looking directive @{\extracolsep{\fill}} directive tells LaTeX to increase the intercolumn whitespace to fill up the available space.

Note that I also suggest moving the common legend to a place above the subtables.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french,english]{babel}
\usepackage{amsmath,booktabs,array,subcaption}
\newcolumntype{C}{>{$}c<{$}}
\newcolumntype{R}{>{$}r<{$}}
\begin{document}
\begin{table}
\captionsetup[subtable]{size=footnotesize,
                        skip=0.25\baselineskip,
                        singlelinecheck=false,
                        justification=raggedright}
\caption{A first very long sentence. 
    a) Name of my first subtable. 
    b) Name of my second subtable. 
    c) Name of my third subtable.} 
\label{tab:scrounging}

\footnotesize

\bigskip
In the following tables, the response variable is the proportion of scrounged patches, expressed as a 2-column matrix  composed of the number of scrounged patches and number of produced patches.

\centering % a single \centering instruction suffices
\setlength\tabcolsep{0pt} % let LaTeX figure out the intercolumn spacing

\bigskip
\begin{subtable}{0.7\textwidth}
\caption{} \label{tbl:sub-table-a}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lCRCR}
\toprule
Fixed effects & \text{Estimate} \pm \text{SE} & \multicolumn{2}{C}{Z} & P \\
\midrule
(Intercept) & -0.27 \pm 0.13 & \multicolumn{2}{C}{-2.10} & 0.036 \\
Trial       & \phantom{-}0.00 \pm 0.05 & \multicolumn{2}{C}{\phantom{-}0.04} & 0.965 \\
\midrule
Random effects & \text{Variance} \pm \text{SD} & \text{LRT} & \text{d.f.} & P \\
\midrule
Bird (intercept) & 0.55 \pm 0.74 & 159 & 1 & < 0.001 \\
Bird (slope with trial) & 0.02 \pm 0.16 & 1.40 & 1 & 0.237 \\
Flock (intercept) & 0.00 \pm 0.00 & 0 & 1 & 1 \\
\midrule
$N = 454$. \\
\end{tabular*}
\end{subtable}   

\bigskip % insert some space between the subtables
\begin{subtable}{0.7\textwidth}
\subcaption{} \label{tbl:sub-table-b}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lCRCR}
\toprule
Fixed effects & \text{Estimate} \pm \text{SE} & \multicolumn{2}{C}{Z} & P \\ 
\midrule 
(Intercept) & -0.26 \pm 0.19 & \multicolumn{2}{C}{-1.39} & 0.166 \\
Trial & \phantom{-}0.04 \pm 0.09 & \multicolumn{2}{C}{\phantom{-}0.44} & 0.659 \\
\midrule 
Random effects & \text{Variance} \pm \text{SD} & \text{LRT} & \text{d.f.} & P \\
\midrule 
Bird (intercept) & 0.60 \pm 0.77 & 81.2 & 1 & < 0.001 \\
Bird (slope with trial) & 0.05 \pm 0.22 & 1.68 & 1 & 0.194 \\
Flock (intercept) & 0.00 \pm 0.00 & 0 & 1 & 1 \\ 
\midrule  
$N = 234$. \\
\end{tabular*}
\end{subtable}

\bigskip
\begin{subtable}{0.7\textwidth}
\subcaption{} \label{tbl:sub-table-c}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lCRCR}
\toprule
Fixed effects & \text{Estimate}\pm\text{SE} & \multicolumn{2}{C}{Z} & P \\ 
\midrule 
(Intercept) & -0.27 \pm 0.17 & \multicolumn{2}{C}{-1.57} & 0.117 \\
Trial & -0.03 \pm 0.07 & \multicolumn{2}{C}{-0.42} & 0.674 \\ 
\midrule 
Random effects & \text{Variance}\pm\text{SD} & \text{LRT} & \text{d.f.} & P \\ 
\midrule
Bird (intercept) & 0.50 \pm 0.71 & 77.5 & 1 & < 0.001 \\
Bird (slope with trial) & 0.01 \pm 0.10 & 0.17 & 1 & 0.682 \\
Flock (intercept) & 0.00 \pm 0.00 & 0 & 1 & 1 \\ 
\midrule  
$N = 220$. \\ 
\end{tabular*}
\end{subtable}

\end{table}
\end{document}
  • Thank you so much for all these suggestions! :-D It is so beautiful! I will come back in a few days with new more questions haha. Thank you!! – user118919 Nov 16 '16 at 21:44
  • Well, I have 3 more questions...: First, is there a mean to have similar gaps between Estimate ± SE and Z, and between Z and P? Same question with Variance ± SD and LRT, LRT and d.f., d.f. and P. Second, is there a mean to put (a), (b), (c) on the same line as Fixed effects? Third, when I use ‘showframe‘, a part of my third subtable is out of the page. Is there a mean to control all the table length? Thanks a lot in advance! :-) – user118919 Nov 17 '16 at 18:39
  • @Bateau - You now have enough reputation points to upvote answers you find useful -- not only on your own postings, by the way. You are also free to "accept" (by clicking on the checkmark symbol) an answer to a question of yours that you find most useful. Incidentally, since your new questions are only loosely related to your previous posting, you should post a new query. That way, it'll be seen by a lot more people who may be able to offer a solution. By the way, what do you mean by "Is there a mean..."? Do you maybe mean, "Is there a method..."? – Mico Nov 17 '16 at 18:41
  • 1
    Thank you for these tips! I'll use my new powers for sure! Yes I meant is there a method to divide more equitably the gap between each column? I don't understand why the last column takes all the width available... – user118919 Nov 17 '16 at 18:51
  • @Bateau - I'll provide an addendum to my answer to address your first follow-up question. For the second follow-up question, please search this site for methods for placing labels in the margins. Regarding your third follow-up question: Since you haven't told us anything about the size of the textblock of your document, I can't give you any concrete advice on what to do. For sure, the entire table environment produced in the answer above fits comfortably in the (default) textblock. – Mico Nov 17 '16 at 19:11
0

A solution with tabularx and siunitx:

\documentclass{book}
\usepackage[utf8]{inputenc}%
\usepackage[T1]{fontenc}%
 \usepackage{lmodern}
\usepackage[french,english]{babel}
\usepackage{booktabs}
\usepackage{tabularx, siunitx}
\sisetup{table-number-alignment=center}
\usepackage{caption, subcaption}
\captionsetup{font=small}
\captionsetup[subtable]{singlelinecheck=off, font=footnotesize}

\begin{document}
\begin{table}[!htbp]
  \caption{A first very long sentence. a) Name of my first subtable. b) Name of my second subtable. c) Name of my third subtable.}
  \footnotesize\setlength{\tabcolsep}{3pt}
  \centering
  \begin{subtable}{0.65\textwidth}
    \subcaption{}\label{tbl:sub-table-a}
    \begin{tabularx}{\linewidth}{X S[table-format=-1.2, separate-uncertainty, table-figures-uncertainty=2] c c S[table-format=1.3, table-comparator]}
      \toprule
      Fixed effects & {Estimate $\pm$ SE} & \multicolumn{2}{c}{Z} & {P} \\
      \midrule %
      (Intercept) & -0.27(13) & \multicolumn{2}{c}{$-2.10 $} & 0.036 \\%
      Trial & 0.00(05) & \multicolumn{2}{c}{$\phantom{-} 0.04 $} & 0.965 \\
      \midrule
      Random effects & {Variance $\pm$ SD} & LRT & d.f. & {P} \\
      \midrule
      Bird (intercept) & 0.55(74) & \multicolumn{1}{r}{159} & 1 & {}< 0.001 \\%
      Bird (slope with trial) & 0.02(16) & \multicolumn{1}{r}{1.40} & 1 & 0.237 \\%
      Flock (intercept) & 0.00(0) & \multicolumn{1}{r}{0} & 1 & {1} \\
      \bottomrule
      \addlinespace[1ex]
      \multicolumn{5}{@{}p{\linewidth}@{}}{N = 454. The response variable is the proportion of scrounged patches, expressed as a 2-column matrix composed of the number of scrounged patches and number of produced patches.\medskip}
    \end{tabularx}
  \end{subtable}

  \begin{subtable}{0.65\textwidth}
    \subcaption{}\label{tbl:sub-table-b}
    \begin{tabularx}{\linewidth}{X S[table-format=-1.2, separate-uncertainty, table-figures-uncertainty=2] c c S[table-format=1.3, table-comparator]}
      \toprule
      Fixed effects & {Estimate $\pm$ SE} & \multicolumn{2}{|c|}{Z} & {P} \\
      \midrule %
      (Intercept) & -0.26(19) & \multicolumn{2}{c}{$ -1.39 $} & 0.166 \\%
      Trial & 0.00(05) & \multicolumn{2}{c}{$\phantom{-} 0.44 $} & 0.659 \\
      \midrule
      Random effects & {Variance $\pm$ SD} & LRT & d.f. & {P} \\
      \midrule
      Bird (intercept) & 0.60(77) & \multicolumn{1}{r}{81.2} & 1 & < 0.001 \\%
      Bird (slope with trial) & 0.05(22) & \multicolumn{1}{r}{1.68} & 1 & 0.194 \\%
      Flock (intercept) & 0.00(0) & \multicolumn{1}{r}{0} & 1 & {1} \\
      \bottomrule
      \addlinespace[1ex]
      \multicolumn{5}{@{}p{\linewidth}@{}}{N =234.\medskip}
    \end{tabularx}
  \end{subtable}

  \begin{subtable}{0.65\textwidth}
    \subcaption{}\label{tbl:sub-table-c}
    \begin{tabularx}{\linewidth}{X S[table-format=-1.2, separate-uncertainty, table-figures-uncertainty=2] c c S[table-format=1.3, table-comparator]}
      \toprule
      Fixed effects & {Estimate $\pm$ SE} & \multicolumn{2}{|c|}{Z} & {P} \\
      \midrule %
      (Intercept) & -0.27(17) & \multicolumn{2}{c}{$ -1.57 $} & 0.117 \\%
      Trial & -0.03(07) & \multicolumn{2}{c}{$ -0.42 $} & 0.674 \\
      \midrule
      Random effects & {Variance $\pm$ SD} & LRT & d.f. & {P} \\
      \midrule
      Bird (intercept) & 0.50(71) & \multicolumn{1}{r}{77.5} & 1 & < 0.001 \\%
      Bird (slope with trial) & 0.01(10) & \multicolumn{1}{r}{0.17} & 1 & 0.682 \\%
      Flock (intercept) & 0.00(0) & \multicolumn{1}{r}{0} & 1 & {1} \\
      \bottomrule
      \addlinespace[1ex]
      \multicolumn{5}{@{}p{\linewidth}@{}}{N =220.}
    \end{tabularx}
  \end{subtable}
\end{table}

\end{document} 

enter image description here

0

Edit: You have partly right :) last multicolum row is to wide. It is defined with linewidth, which defined with width of subtable. If you shorten it to 77mm, the table will appear as you wish.

enter image description here

Regarding subcaption position, I understand, that you like to have them left of table, aligned with first table row. This can be achieved with use of floatrow and use subfig package instead of subcaption.

I now also exploit presence of booktabs for horizontal rule and add makecell for defining column's heads with its macro thead.

For equal width of all sub tables is sensible to use tables' environments with prescribed width as they are tabularx and tabular*. Use of `tabular is simpler. For their width I suggest to define new length (see MWE below) by which you can set all sub tables width in one place.

In estimation of appropriate table width I help myself with showframe package which show page layout. Of course, in final document this package had to be removed from preamble.

Of-topic: your table is unnecessary complicated. I remove all of multicolumns except those which span two columns. Also tables with font size \script is difficult to read, so I suggest to use bigger ones.

Complete, new MWE which contain only the first table, is:

\documentclass{book}
\usepackage[french,english]{babel}

\usepackage{booktabs, makecell, tabularx}% <--- added makecell
    \renewcommand\theadfont{\footnotesize}
    \newcommand\mc[2]{\multicolumn{#1}{c}{#2}}
    \newcommand\mr[1]{\multicolumn{1}{r}{#1}}
    \newlength\tabwidth
\usepackage{floatrow}% <-- added for side position of subcaptions
\floatsetup[table]{style=plain,subcapbesideposition=top,capposition=top}
\usepackage{caption}
\usepackage[label font=bf,labelformat=parens]{subfig}
\usepackage{calc}% <-- added for calculation of cell width

\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
    \begin{table}[]
\caption{A first very long sentence. a) Name of my first subtable. b) Name of my second subtable. c) Name of my third subtable.}
    \label{tbl:sub-table-a}
\centering
\setlength\tabwidth{90mm}
\footnotesize
\sidesubfloat[]{
\begin{tabularx}{\tabwidth}{X c c c r}
    \toprule
\thead{Fixed effects}
                & \thead{Estimate $\pm$ SE}
                                    & \mc{2}{\thead{Z}}     & \thead{P} \\
    \midrule
(Intercept)     & -0.27 $\pm$ 0.13  & \mc{2}{-2.10} & 0.036             \\
Trial           & 0.00 $\pm$ 0.05   & \mc{2}{0.04}  & 0.965             \\
    \midrule
\thead{Random effects}
                & \thead{Variance $\pm$ SD} 
                                    & \thead{LRT}   & \thead{d.f.}  
                                                            & \thead{P} \\
    \midrule
Bird (intercept)& 0.55 $\pm$ 0.74   & \mr{159}      & 1     & $<$ 0.001 \\
Bird (slope with trial)
                & 0.02 $\pm$ 0.16   & \mr{1.40}     & 1     &  0.237    \\
Flock (intercept)
                & 0.00 $\pm$ 0.00   & \mr{0}        & 1     & 1         \\
    \midrule[1pt]
\multicolumn{5}{p{\tabwidth-2\tabcolsep}}{N = 454. The response variable is the proportion of scrounged patches, expressed as a 2-column matrix composed of the number of scrounged patches and number of produced patches.}
\end{tabularx}
}   
    \end{table}
\end{document}
  • Thank you so much for your help! May I ask you why the right width is 77mm? What calculation did you make? :-) And last thing, how could I put the a), b), c) at the left, aligned with "Fixed effects" please? Again, thanks a lot! :-D – user118919 Nov 16 '16 at 20:33
  • to much questions ... :). (i) if you add showframe package (it show page layout) in preamble of your document, than is not difficult to estimate table width, (ii) this question was asked before: see tex.stackexchange.com/questions/20354 . – Zarko Nov 16 '16 at 20:43
  • Ok for the showframe, but did you try 80mm, 79mm, 78mm, etc... or did you do a calculation that I miss? :-) Thanks for the other link! – user118919 Nov 16 '16 at 21:16
  • 77 is magic number: you need to stroke twice the same key :). well, 80 mm is also fine. See edit of my answer. – Zarko Nov 16 '16 at 21:25
  • Haha it is a good point for 77. Thanks Zarko for the addendum, I will take a closer look at it :-) – user118919 Nov 16 '16 at 21:47

Your Answer

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