[Tex/LaTex] Using LyX, how do you put a table and a figure side by side and caption them Table XX and Figure XX

captionsfloatslyxtables

I have found solutions for them to be done in normal TeX, but how do I do this in LyX? What I wish to obtain is something like that shown in Table and Figure side-by-side with Table caption above, Figure caption below

I have tried doing this by creating a mini-page and putting two boxes inside, but the table keeps getting captioned as a sub-figure instead of a table.

Best Answer

You can use minipages as you first tried, if you add the capt-of (or caption) package and write the caption in an ERT using captionof command, which has the syntax

\captionof{<float type>}{<caption>}

So, in LyX:

  1. Document --> Settings --> LaTeX preamble, add either

    \usepackage{capt-of}
    

    (or \usepackage{caption})

  2. Insert a figure float, with Insert --> Float --> Figure or the button on the toolbar.
  3. Delete the caption that is there by default (just place the cursor outside it, and hit backspace or delete).
  4. Add two minipages with Insert --> Boxes --> Frameless. Add the second one immediately after the first one, do not hit enter after the first one.
  5. Set the width of both to just below half the line width, e.g. 49% of the line width.
  6. In the minipage where you want the figure, add a new caption with Insert --> Caption. Add the image above it, as you normally would.
  7. In the minipage where you want the table, add an ERT with Ctrl + L or Insert --> TeX Code, and write

    \captionof{table}{Your table caption}
    

    Add the table below the caption as you normally would.

    Optionally, you could write

    \captionsetup{type=table}
    

    in the ERT, and add the caption outside the ERT with Insert --> Caption. Make sure the ERT is placed before the caption. Note that this will not change the caption type in the LyX GUI, there you'll still have two figure captions, but in the PDF it will be correct. This also makes it easier to add cross references or citations in the caption, as you can use the GUI for that.

You may have to change the vertical alignment of the minipages as well, which you can do in the settings for the Inset. In the image below, the right minipage has the vertical alignment for the Box set to Middle, all other vertical alignments are set to Top.

enter image description here

Related Question