1

I'm trying to decently put a figure right next to a table. I tried all the approaches suggested here and here. None of them worked.

The closest was the first one, but I get an error Package floatrow Error: Caption(s) lost at the \captionof{figure} line.

Code:

\documentclass{article}

\usepackage[demo]{graphicx} \usepackage{floatrow} \usepackage{caption}

\begin{document} \begin{table} \begin{minipage}{0.45\textwidth} % \setlength{\tabcolsep}{4pt} % \scriptsize \caption{Wind turbulence characteristic values.} \begin{tabular}{| c | c | c | c | c |} \hline {} & $\overline{U}$ & $u(t)$ & $v(t)$ & $w(t)$ \ \hline $\mu$ [m/s] & 49.7 & 0 & 0 & 0 \ \hline $\sigma$ [m/s] & - & 6.34 & 4.76 & 3.17 \ \hline L${x}$ [m] & - & 120 & 30 & 10 \ \hline L${y}$ [m] & - & 40 & 30 & 7.5 \ \hline L${z}$ [m] & - & 30 & 7.5 & 7.5 \ \hline C${x}$ & - & 12 & 12 & 12 \ \hline C${y}$ & - & 6 & 6 & 6 \ \hline C${z}$ & - & 9 & 9 & 9 \ \hline \end{tabular} \end{minipage} \hfill \begin{minipage}{0.45\textwidth} \includegraphics{graphs/dataset17b.pdf} \captionof{figure}{Caption figure} \label{fig:ravine_coeffs} \end{minipage} \end{table} \end{document}

Current result:

enter image description here

EDIT: I'd also need to make references to both, so I'd need to put \labels.

mEm
  • 113
  • Have you tested the examples from the linked questions unchanged? Do they work? Can you please extend your code snippet to a minimal working example, that can be copied to reproduce your problem without guessing how to extend it to compile? You should also replace the image file, which we do not have (see the link above), e.g., using an example image from package mwe. – cabohah Mar 22 '24 at 08:40
  • @cabohah I will provide a MWE soon. Yes, I did try a standalone version of the first link. It does not even compile for me. – mEm Mar 22 '24 at 08:45
  • Why a table cannot be inside a minipage is already explained in the first sentence of the answer to the question in your first link: table is a float. The specification of floats is to float outside the environments. Floats cannot be used inside boxes. A minipage is a special kind of box. – cabohah Mar 22 '24 at 08:46
  • 1
    BTW: If you are using package floatrow, you should read the manual. The package provides it own environment floatrow and commands \ttabbox and \ffigbox to place tables and figures side by side – cabohah Mar 22 '24 at 08:50
  • Ok, the MWE is now behaving as expected. I guess it is a problem related to the \documentclass. – mEm Mar 22 '24 at 08:53
  • Sorry, but in this case, the MWE is not a MWE, but useless. A MWE should always show the problem. – cabohah Mar 22 '24 at 08:55
  • I will delete the question – mEm Mar 22 '24 at 08:56
  • You don't need to delete the question. Just show a MWE, that shows the problem. If the problem depends on a package or class, show this. See the first link in my first comment. – cabohah Mar 22 '24 at 08:57
  • @cabohah you should now have a MWE. I included the floatrow package and now the problem shows. Thanks for being patient! – mEm Mar 22 '24 at 09:02
  • 1
    Needless to say, this is much simpler without floatrow, but may still have prolems WRT hyperref (see https://tex.stackexchange.com/questions/643473/unexpected-table-figure-reference) – John Kormylo Mar 22 '24 at 14:55
  • @JohnKormylo thanks for your comment. Yes, I realised it while trying to make one of the referenced cases work. Without it, it works like a charm. Unfortunately, I need to use a class which uses it under-the-hood. For the moment, I managed to solve it, also considered that I'm running out of time for what I needed it to work. On a later moment, I will certainly documeny myself better on this matter. – mEm Mar 24 '24 at 14:48

1 Answers1

1

As already told in a comment: If you use package floatrow, you should use the package's feature to place floating contents side by side. So you should use the floatrow environment and commands like \ttabbox, \ffigbox, \floatbox etc.

For example you could use something like:

\documentclass{article}

\usepackage[demo]{graphicx} \usepackage{floatrow} \usepackage{caption}

\begin{document} \begin{table}% table* does only make sense with option twocolumn or command \twocolumn \begin{floatrow} \TopFloatBoxes\ttabbox{\caption{Wind turbulence characteristic values.}} {\begin{tabular}{| c | c | c | c | c |} \hline {} & $\overline{U}$ & $u(t)$ & $v(t)$ & $w(t)$ \ \hline $\mu$ [m/s] & 49.7 & 0 & 0 & 0 \ \hline $\sigma$ [m/s] & - & 6.34 & 4.76 & 3.17 \ \hline L${x}$ [m] & - & 120 & 30 & 10 \ \hline L${y}$ [m] & - & 40 & 30 & 7.5 \ \hline L${z}$ [m] & - & 30 & 7.5 & 7.5 \ \hline C${x}$ & - & 12 & 12 & 12 \ \hline C${y}$ & - & 6 & 6 & 6 \ \hline C${z}$ & - & 9 & 9 & 9 \ \hline \end{tabular}} % \killfloatstyle \ffigbox{\caption{Caption figure}\label{fig:ravine_coeffs}} {\includegraphics{graphs/dataset17b.pdf}} \end{floatrow} \end{table} \end{document}

to get

table and figure side by side top aligned.

See the floatrow manual for more information, e.g., about vertical alignment using \TopFloatBoxes, \CenterFloatBoxes, \BottomFloatBoxes, nested boxes, \killfloatstyle and all the options and features the package provides.

cabohah
  • 11,455
  • Thanks @cabohah ! How to control boxes dimensions ? The figure goes out of the document. I tried forcing the width with \ffigbox[0.4\textwidth] but does nothing. – mEm Mar 22 '24 at 09:25
  • 1
    BTW: I've never used floatrow before. I've just spend some minutes to read parts of the manual. So maybe my code could be improved. And yes, the tabular code can be improved: Don't use vertical lines in tables unless you really, really need them. Reduce horizontal lines in tables to a minimum. Tables with line matrices are difficult to read and ugly. – cabohah Mar 22 '24 at 09:25
  • Read the manual. The \floatbox command (and therefore also \ffigbox and \ttabbox) has optional arguments for width, height etc. – cabohah Mar 22 '24 at 09:27
  • That's why I asked.. I read, tried, but nothing changed.. Thanks anyway fo rthe help. I see if I figure that out. – mEm Mar 22 '24 at 09:30
  • 1
    Without knowing, what you've tried, I can only guess: The optional width argument of \ffixbog does not change the height or width values of options the width and height of \includegraphics. It only changes the width and height of the box. And if you have more problems, please ask more questions (with corresponding MWE). – cabohah Mar 22 '24 at 09:32