1

When I put the table and figure in two separate enviroments, they fit nicely to one column like this.

enter image description here

However, when I put them in minipage as one float the figure and table become misaligned and the table is bigger than the \linewidth.

enter image description here

How can I fix this? I want to put them into one float with two separate captions like that.

\documentclass[journal]{IEEEtran}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{booktabs,capt-of}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
%
 \begin{table}[!t]
    \centering
    \caption{a table}
    \label{tab:a table}
    \begin{tblr}{
            colspec={Q[2.35em,c] *7{Q[2.34em,c]}},
            vline{1} = {2-Z}{0.8pt},
            vline{2,Z} = {0.8pt},
            vline{3-Y} = {0.3pt},
            hline{1} = {2-Z}{0.8pt},
            hline{2,Z} = {0.8pt},
            hline{3-Y} = {0.3pt},
            row{1-8} = {mode=math},
            column{1-8} = {mode=math},
        }
        & V_1 &  V_2 & V_3 & V_4 & V_5  & V_6 & V_7\\
        V_1 &   & 1 & 0 & 0 & 1 & 0 & 1\\
        V_2 & 1 & 0 & 1 & 0 & 1 & 0 & 1\\
        V_3 & 0 & 1 & 0 & 1 & 0 & 0 & 1\\
        V_4 & 0 & 0 & 1 & 0 & 1 & 0 & 1\\
        V_5 & 1 & 1 & 0 & 1 & 0 & 0 & 1\\
    \end{tblr}
  \end{table}
  
 \begin{figure}
     \centering
    \includegraphics[width=\linewidth]{example-image-a}
     \caption{a figure}
     \label{fig:my_label}
 \end{figure}
\lipsum[1]
\lipsum[1]


  \begin{minipage}{\linewidth}
  \begin{minipage}[b]{\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-a}
    \label{fig:a figure}
    \captionof{figure}{a figure}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{\linewidth}
      \captionof{table}{a table}
    \label{tab:a table}
    \begin{tblr}{
            colspec={Q[2.35em,c] *7{Q[2.34em,c]}},
            vline{1} = {2-Z}{0.8pt},
            vline{2,Z} = {0.8pt},
            vline{3-Y} = {0.3pt},
            hline{1} = {2-Z}{0.8pt},
            hline{2,Z} = {0.8pt},
            hline{3-Y} = {0.3pt},
            row{1-8} = {mode=math},
            column{1-8} = {mode=math},
        }
        & V_1 &  V_2 & V_3 & V_4 & V_5  & V_6 & V_7\\
        V_1 &   & 1 & 0 & 0 & 1 & 0 & 1\\
        V_2 & 1 & 0 & 1 & 0 & 1 & 0 & 1\\
        V_3 & 0 & 1 & 0 & 1 & 0 & 0 & 1\\
        V_4 & 0 & 0 & 1 & 0 & 1 & 0 & 1\\
        V_5 & 1 & 1 & 0 & 1 & 0 & 0 & 1\\
    \end{tblr}
    \end{minipage}
  \end{minipage}
\lipsum[1]
\end{document}                        

1 Answer 1

1

The IEEE uses 8pt text for tables and its is necessary to add \noindent to suppress the paragraph indent before the first minipage.

\noindent\begin{minipage}{\linewidth}
        \begin{minipage}[b]{\linewidth}
            \centering
            \includegraphics[width=\linewidth]{example-image-a}
            \captionof{figure}{a figure}\label{fig:a figure}
        \end{minipage}
        \hfill
        \begin{minipage}[b]{\linewidth}     
            \captionof{table}{a table}\label{tab:a table}
            \footnotesize %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<,
            \begin{tblr}{
                    colspec={Q[2.35em,c] *7{Q[2.34em,c]}},
                    vline{1} = {2-Z}{0.8pt},
                    vline{2,Z} = {0.8pt},
                    vline{3-Y} = {0.3pt},
                    hline{1} = {2-Z}{0.8pt},
                    hline{2,Z} = {0.8pt},
                    hline{3-Y} = {0.3pt},
                    row{1-8} = {mode=math},
                    column{1-8} = {mode=math},
                }
                & V_1 &  V_2 & V_3 & V_4 & V_5  & V_6 & V_7\\
                V_1 &   & 1 & 0 & 0 & 1 & 0 & 1\\
                V_2 & 1 & 0 & 1 & 0 & 1 & 0 & 1\\
                V_3 & 0 & 1 & 0 & 1 & 0 & 0 & 1\\
                V_4 & 0 & 0 & 1 & 0 & 1 & 0 & 1\\
                V_5 & 1 & 1 & 0 & 1 & 0 & 0 & 1\\
            \end{tblr}
        \end{minipage}
    \vspace*{\baselineskip} %<<<<<<<<<<<<<<<
    \end{minipage}
\lipsum[1]

a

8
  • Very nice, how would you set the position top? I tried \noindent\begin{minipage}[!t]{\linewidth} but it didn't work.
    – emnha
    Sep 13, 2022 at 20:35
  • @emnha The minipage is not a float. It goes where you put it. Sep 13, 2022 at 20:37
  • Oh, that is a bad new. I thought it is float. Is there a simple fix for this or should I start a new thread?
    – emnha
    Sep 13, 2022 at 20:38
  • @emnha What exactly do you want to achieve? Tables and figures are floats. You can keep the together as in the first column. Sep 13, 2022 at 20:43
  • 1
    @emnha It will be better to ask another question. Be careful with the document class you choose. IEEEtran it is heavily customize with floats. Sep 13, 2022 at 20:48

You must log in to answer this question.

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