TransWikia.com

Side by side subfigures in lyx

TeX - LaTeX Asked by Nischal Karki on February 13, 2021

I am using lyx and want to put two figures side by side. I could do it by inserting two minipages separated by a hfill inside a float but it only allows me to use separate captions rather than subcaptions (I want it to be labeled as fig 1a, fig 1b). Also by inserting float inside a float, the 2nd figure appeared below the first one rather than in side. Any tips would be really helpful.

3 Answers

For anyone having the same problem, I found a solution which apparently worked for me in lyx:

  1. Insert> Float > Figure
  2. Insert > Box > Frameless.
  3. Right click on minipage and go to settings. Set width to 45 column width%
  4. Click right next to the minipage (not inside). Go to Insert> Formatting> Horizontal space and select horizontal fill in spacing.
  5. Repeat step2 and add graphics in both minipages.
  6. Go to Document> Settings > LaTex Preamble and add usepackage{subcaption}
  7. Inside each minipage, Insert tex code subcaption{Your subcaption here}

Answered by Nischal Karki on February 13, 2021

The better approach I found, was to use subfigures (especially when you want to refer to subfigures as 1a or 1b. From the LaTeX FAQ:

  • Insert→Float→Figure
  • Again, Insert→Float→Figure (this inserts a "subfigure float" into the float)
  • Put the cursor right next to the subfloat
  • Insert→Formatting→Horizontal Space→Horizontal Fill or Ctrl- -> right-click on space -> select "Horizontal Fill" (to insert a stretchable horizontal space)
  • Insert→Float→Figure (this inserts another "subfigure float")
  • In each subfloat:add the graphics and edit the caption
  • To insert a vertical space, Insert→Formatting→Vertical Space→DefSkip.

Or if you could just use this code (this is LyX syntax; not LaTeX) from what I created (you may have to right click on the images and adjust the width % of the images):

begin_layout Standard
begin_inset Float figure
wide false
sideways false
status open

begin_layout Plain Layout
begin_inset Float figure
wide false
sideways false
status open

begin_layout Plain Layout
begin_inset Graphics
    filename images/Fig2_1.png
    scale 30

end_inset


end_layout

begin_layout Plain Layout
begin_inset Caption Standard

begin_layout Plain Layout
Name1
begin_inset CommandInset label
LatexCommand label
name "fig:label1"

end_inset


end_layout

end_inset


end_layout

end_inset


begin_inset space hfill{}
end_inset


begin_inset Float figure
wide false
sideways false
status open

begin_layout Plain Layout
begin_inset Graphics
    filename images/Fig2_2.png
    scale 30

end_inset


end_layout

begin_layout Plain Layout
begin_inset Caption Standard

begin_layout Plain Layout
Name2
begin_inset CommandInset label
LatexCommand label
name "fig:Name2"

end_inset


end_layout

end_inset


end_layout

end_inset


begin_inset VSpace defskip
end_inset


end_layout

begin_layout Plain Layout
begin_inset Float figure
wide false
sideways false
status open

begin_layout Plain Layout
begin_inset Graphics
    filename images/Fig2_3.png
    scale 30

end_inset


end_layout

begin_layout Plain Layout
begin_inset Caption Standard

begin_layout Plain Layout
Name3
begin_inset CommandInset label
LatexCommand label
name "fig:Name3"

end_inset


end_layout

end_inset


end_layout

end_inset


begin_inset space hfill{}
end_inset


begin_inset Float figure
wide false
sideways false
status open

begin_layout Plain Layout
begin_inset Graphics
    filename images/Fig2_4.png
    scale 30

end_inset


end_layout

begin_layout Plain Layout
begin_inset Caption Standard

begin_layout Plain Layout
Name3
begin_inset CommandInset label
LatexCommand label
name "fig:Name3"

end_inset


end_layout

end_inset


end_layout

end_inset


end_layout

begin_layout Plain Layout
begin_inset Caption Standard

begin_layout Plain Layout
Caption for figure
begin_inset CommandInset label
LatexCommand label
name "fig:FigureLabel"

end_inset


end_layout

end_inset


end_layout

end_inset

 
end_layout

For doing the same thing in pure LaTeX:

begin{figure}[tb]
begin{center}
subfigure[Name1]{includegraphics[width=1.625in]{images/Fig2_1.png}}
subfigure[Name2]{includegraphics[width=1.625in]{images/Fig2_2.png}}
subfigure[Name3]{includegraphics[width=1.625in]{images/Fig2_3.png}}
subfigure[Name4]{includegraphics[width=1.625in]{images/Fig2_4.png}}
end{center}
caption{Caption for figure}
label{figureLabel}
end{figure}

Answered by Nav on February 13, 2021

I could not get the above to work. A (low-brow?) way to do this is with a table, ie to make:

begin{figure}
centering{}%
begin{tabular}{cc}
includegraphics[width=7cm]{image1} & includegraphics[width=7cm]{image2}tabularnewline
(a) & (b)tabularnewline
end{tabular}caption{foiw}
end{figure}

For that I just

  1. Insert Figure
  2. Insert 2x2 tabular
  3. Insert Graphics inside each cell in the top row
  4. Write (a) and (b) in the lower row cells (or longer captions if you like)
  5. Select all four cells and turn off all borders
  6. Select the tabular and right-click and change paragraph to centered

With this, you can add a referencing label to the overall figure, but not separately to each subfigure. You would just use, e.g. Figure~ref{myfig}(a)

Answered by CPBL on February 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP