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?

hana
  • 759
  • 2
  • 9

1 Answers1

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.

mmr
  • 2,249
  • 5
  • 22
  • Thanks, I saw subfig but I thought it is only for figures not tables? – hana Jun 07 '22 at 04:40
  • @hana You can also use \begin{minipage}. – mmr Jun 07 '22 at 04:43
  • I copied the minipage code from here. https://tex.stackexchange.com/questions/157222/putting-figures-side-by-side-using-minipage And I want to make it with \begin{figure} and table from booktabs but couldn't make it work. – hana Jun 08 '22 at 06:12
  • @hana Can you give me your latest code MWE for clear understanding. – mmr Jun 08 '22 at 06:15
  • Here is my code and you can use any figure. https://pastebin.com/XSBnZTaS – hana Jun 08 '22 at 06:26
  • @hana I have updaed the answer. Plz look at this. – mmr Jun 08 '22 at 07:11
  • Thanks, it kinds of work but for the table I got a caption like this "Fig. 2. Company" which is not quite right. I want to format it as a table such as TABLE 1. COMPANY and it would be nice if these figure and table can be indexed automatically as well. – hana Jun 08 '22 at 07:20
  • @hana Just updated the issue, you can check it now. (the latest update) Using caption package you can fix it easily. thanks – mmr Jun 08 '22 at 07:33
  • Thanks, and I know I asked too much but I promise this is the last question. The image and table seem like to be aligned by top. What if I align bottom or middle align them? https://ibb.co/vHrTdjf – hana Jun 08 '22 at 07:43
  • 1
    I just found a solution here. https://tex.stackexchange.com/questions/66109/aligning-a-figure-and-table-side-by-side – hana Jun 08 '22 at 07:49