0

I copied the floatrow code from this and couldn't make it work with the two columns layout.

\documentclass[journal]{IEEEtran}
\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{array}
\usepackage[caption=false,font=normalsize,labelfont=sf,textfont=sf]{subfig}
\usepackage{textcomp}
\usepackage{stfloats}
\usepackage{url}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{cite}
\hyphenation{op-tical net-works semi-conduc-tor IEEE-Xplore}
% updated with editoria
\usepackage{parskip}
\usepackage{mathtools}
\usepackage{floatrow}
\usepackage[demo]{graphicx}

\documentclass{article}

\usepackage{floatrow}
% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\usepackage{blindtext}

\begin{document}

\blindtext

\begin{figure}
\begin{floatrow}
\ffigbox{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}
\capbtabbox{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}
}{%
  \caption{A table}%
}
\end{floatrow}
\end{figure}

\end{document}

enter image description here

How can I fix this?

3
  • you can accept the answer as useful.
    – mmr
    Commented Jun 7, 2022 at 19:02
  • @topu thanks, I really appericate it. May I ask about applying subfig before accepting it?
    – hana
    Commented Jun 8, 2022 at 5:56
  • Sure. Go ahead.
    – mmr
    Commented Jun 8, 2022 at 6:07

1 Answer 1

1

There are many ways you can fix it. I suggest you to rearrange your code as:

\documentclass[journal]{IEEEtran}

\usepackage{floatrow}
% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{array}
\usepackage{textcomp}
\usepackage{stfloats}
\usepackage{url}
\usepackage{verbatim}

\usepackage{cite}
\hyphenation{op-tical net-works semi-conduc-tor IEEE-Xplore}
% updated with editoria
\usepackage{parskip}
\usepackage{mathtools}

\usepackage{blindtext}

\begin{document}

\blindtext

\begin{figure}
\begin{floatrow}
\ffigbox{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}
\capbtabbox{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}
}{%
  \caption{A table}%
}
\end{floatrow}
\end{figure}

\end{document}

Is this Ok now? You can also use \subfig to make a figure and table side by side.

Update

Here is another way using minipage.

MWE:

\documentclass[journal]{IEEEtran}

\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{array}
\usepackage[caption=false,font=normalsize,labelfont=sf,textfont=sf]{subfig}
\usepackage{textcomp}
\usepackage{stfloats}
\usepackage{url}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{cite}
\hyphenation{op-tical net-works semi-conduc-tor IEEE-Xplore}
% updated with editoria
\usepackage{parskip}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{float}
\usepackage{caption}

\begin{document}

\begin{figure}
    \centering
    \rule{2.8cm}{2cm}
    \caption{Caption}
    \label{fig:my_label}
\end{figure}

\begin{figure}[!h]
    %\centering
    \begin{minipage}{.5\linewidth}
        \centering
        \rule{2.8cm}{2cm}
        \captionof{figure}{Figure}
        \label{fig:my_label}
    \end{minipage}%
    \hfill
    \begin{minipage}{.5\linewidth}
          \captionof{table}{Table}
          \label{tab:table1}
          \begin{tabular}{ c c c }
           \toprule
            Name & Age & Height\\ \midrule
            John & 29 & 180         \\\midrule
            Baker & 35 & 170         \\\midrule
            Allen & 60 & 175         \\\bottomrule
          \end{tabular}
    \end{minipage}
\end{figure}


\begin{table}[!h]
    \caption{Caption}
    \label{tab:my_label}
    \centering
    \begin{tabular}{ | c|c |}
        x & y \\
    \end{tabular}
    
\end{table}
\end{document}

You have raised several issues in your code. Be careful about using a lot of package file while using.

Thanks.

10
  • Thanks, I saw subfig but I thought it is only for figures not tables?
    – hana
    Commented Jun 7, 2022 at 4:40
  • @hana You can also use \begin{minipage}.
    – mmr
    Commented Jun 7, 2022 at 4:43
  • I copied the minipage code from here. tex.stackexchange.com/questions/157222/… And I want to make it with \begin{figure} and table from booktabs but couldn't make it work.
    – hana
    Commented Jun 8, 2022 at 6:12
  • @hana Can you give me your latest code MWE for clear understanding.
    – mmr
    Commented Jun 8, 2022 at 6:15
  • 1
    I just found a solution here. tex.stackexchange.com/questions/66109/…
    – hana
    Commented Jun 8, 2022 at 7:49

You must log in to answer this question.

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