3

I have created two table side by side with minipage. the tables appear perfectly except the label and caption for the right table show up as that of left table. On the other hand, the caption and label for right table vanish.

Here's the code:

\documentclass[12pt,a4paper,landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[paper=portrait,pagesize]{typearea}
\usepackage{mathtools}% http://ctan.org/pkg/mathtools
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{float}
\restylefloat{table}


\begin{document}    
\begin{table}[H]
\setlength\tabcolsep{0pt}
\begin{minipage}{0.475\textwidth}
\begin{tabular*}{1\textwidth}{@{\extracolsep{\fill}} l *{8}{c}}
\toprule
Original Class & \multicolumn{8}{c}{Class Predicted} \\
\cmidrule{2-9}
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8  \\
\midrule
1 & 17 & 0 & 0 & 0 & 0  & 0  & 0 & 0 \\
2 & 0 & 14 & 0 & 0 & 0 & 0 & 0 & 0 \\
3 & 0 & 0 & 17 & 0 & 0 & 0 & 0 & 0 \\
4 & 0 & 0 & 0 & 17 & 0 & 0 & 0 & 0  \\
5 & 0 & 0 & 0 & 0 & 15 & 0 & 0 & 0  \\
6 & 0 & 0 & 0 & 0 & 1 & 11 & 0 & 0  \\
7 & 0 & 0 & 0 & 0 & 0 & 0 & 13 & 0  \\
8 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 15  \\
\bottomrule
\end{tabular*}
\caption{Confusion Matrix}
\label{tab:Table 1}
\end{minipage}
\hfill
\begin{minipage}{0.475\textwidth}
\begin{tabular*}{1\textwidth}{@{\extracolsep{\fill}} l *{8}{c}}
\toprule
& \multicolumn{8}{c}{Class} \\
\cmidrule{2-9}
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8  \\
\midrule
TPR & 1 & 1 & 1 & 1 & 1  & 0.917  & 1 & 1 \\
TNR & 1 & 1 & 1 & 1 & 0.99 & 1 & 1 & 1 \\
FPR & 0 & 0 & 0 & 0 & 0.0095 & 0 & 0 & 0 \\
FNR & 0 & 0 & 0 & 0 & 0 & 0.083 & 0 & 0  \\
\bottomrule
\end{tabular*}
\caption{Evaluation Metrics}
\label{tab:Table 2}
\end{minipage}
\end{table}
\end{document}

Output:

enter image description here

Edit

I used the answer written by Mico here.

Edit 2

I have used [ht!] for one table and the table was misplaced (Output attached). So I'm still using [H] which gives me desired output.

enter image description here

13
  • 1
    unrelated but it's not normally good practice to have the table numbers numbers in \label as it confusers people reading the source if \ref{tab:Table 2} produces "Table 4" or whatever the number is in the final document. Commented Sep 27, 2020 at 10:20
  • 1
    the issue is \restylefloat{table} Commented Sep 27, 2020 at 10:28
  • 2
    That makes \caption work as @Marijn described, the \caption is not used where it appears in the source but positioned according to the float style. If you want that generally but need special formatting here then that is probably possible I'd need to check the package but just removing that line gives the output you intended Commented Sep 27, 2020 at 10:30
  • 2
    Incidentally, the directive \usepackage[paper=portrait,pagesize]{typearea} directly contradicts the document class option landscape. Please settle the portrait versus landscape orientation issue.
    – Mico
    Commented Sep 27, 2020 at 10:57
  • 2
    No you only need to load the package to use H restyling floats is more invasive it changes the way tables work, as you found Commented Sep 27, 2020 at 11:28

2 Answers 2

4

As you've found out in the meantime, running \restylefloat is the cause of the odd-ball formatting issue you've encountered. Incidentally, it is not true that it's necessary to run \restylefloat in order to use the [H] positioning specifier with table or figure floats. That said, you should really ask yourself if you're doing the right thing -- typographically speaking -- by using [H] at all, as its use can have some unexpected negative side-effects. Everything good about [H] can also be achieved with [ht!]. For a longer discussion of this issue, see 'h' float specifier changed to 'ht' warning when not attempting to specify a float.

As you've probably also noticed by now, if two minipage environments of unequal heights are placed side by side, their default vertical orientation is to align them verically in the middle. If this is not desired and, say, if you prefer top-alignment, just specify [t] ("top") for both minipage as well as for both tabular* environments.

enter image description here

\documentclass[12pt,a4paper,%landscape % <-- landscape option is overridden
     ]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
%%%\usepackage{amsmath}  % is loaded automatically by 'mathtools'
%%%\usepackage{amsfonts} % is loaded automatically by 'amssymb'
\usepackage{amssymb}
\usepackage[margin=2cm]{geometry}
\usepackage[paper=portrait,pagesize]{typearea}
\usepackage{mathtools}
%%%\usepackage{amsmath} % don't load packages twice
\usepackage{booktabs}
%%%\usepackage{float}   % you don't really need this package
%%%\restylefloat{table} % don't do this


\begin{document}    
\begin{table}[ht!]  % much safer than "[H]"
\setlength\tabcolsep{0pt}
\begin{minipage}[t]{0.475\textwidth}
\begin{tabular*}{1\textwidth}[t]{@{\extracolsep{\fill}} l *{8}{c}}
\toprule
Orig.\ Class & \multicolumn{8}{c}{Class Predicted} \\
\cmidrule{2-9}
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8  \\
\midrule
1 & 17 & 0 & 0 & 0 & 0  & 0  & 0 & 0 \\
2 & 0 & 14 & 0 & 0 & 0 & 0 & 0 & 0 \\
3 & 0 & 0 & 17 & 0 & 0 & 0 & 0 & 0 \\
4 & 0 & 0 & 0 & 17 & 0 & 0 & 0 & 0  \\
5 & 0 & 0 & 0 & 0 & 15 & 0 & 0 & 0  \\
6 & 0 & 0 & 0 & 0 & 1 & 11 & 0 & 0  \\
7 & 0 & 0 & 0 & 0 & 0 & 0 & 13 & 0  \\
8 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 15  \\
\bottomrule
\end{tabular*}
\caption{Confusion Matrix}
\label{tab:Table1}
\end{minipage}
\hfill
\begin{minipage}[t]{0.475\textwidth}
\begin{tabular*}{1\textwidth}[t]{@{\extracolsep{\fill}} l *{8}{c}}
\toprule
& \multicolumn{8}{c}{Class} \\
\cmidrule{2-9}
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8  \\
\midrule
TPR & 1 & 1 & 1 & 1 & 1  & 0.917  & 1 & 1 \\
TNR & 1 & 1 & 1 & 1 & 0.99 & 1 & 1 & 1 \\
FPR & 0 & 0 & 0 & 0 & 0.0095 & 0 & 0 & 0 \\
FNR & 0 & 0 & 0 & 0 & 0 & 0.083 & 0 & 0  \\
\bottomrule
\end{tabular*}
\caption{Evaluation Metrics}
\label{tab:Table2}
\end{minipage}
\end{table}
\end{document}
1
  • Your answer solved my purpose. Also thanks for pointing out unnecessary/redundant use of packages. I removed them. Plz look into Edit 2 portion in my question.
    – Debbie
    Commented Sep 28, 2020 at 9:03
3

It's a hidden feature in float that, when you do \restylefloat, the \caption command changes in a peculiar way: it stores its argument in a box which is assigned globally; only at \end{table} the box is used, which means that the first caption has been forgotten.

The package does so because it wants to enforce top or bottom position of the caption independently on the position the code for \caption is typed at. In the case of the plain style the position is bottom.

The effect of this is that after \restylefloat{table} you cannot use minipage to set two tables side by side.

Too bad, I agree.

On the other hand, you don't need to \restylefloat if you want to use [H] and you don't want to use [H] under any circumstances.

2
  • Hi, thanks for your answer. Plz look into the edit 2 portion of my question.
    – Debbie
    Commented Sep 29, 2020 at 7:25
  • @Debbie Move the code for the table earlier in the document, add also b to the options. When the document is in final form, as far as text is concerned, you may need to add \clearpage before the references. Don’t work on float positioning until your document is in final form, as a general rule.
    – egreg
    Commented Sep 29, 2020 at 7:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .