Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

LyX /

Figures

<< | Page list | >>

Frequently Asked Questions about Figures and Graphics

§1.  What is the difference between a "figure" and a "figure float"?

This is an example of less-than-ideal terminology. "Figure" is what I would really call a "graphic"; it basically means insert a picture file. "Figure float" is more what one means by a figure in a paper: it includes the graphic, the caption, the figure label, etc. You should almost always insert a figure float first, then put a figure inside that.

Tables work in the same manner. Put a table float in first, then insert the table within that.

§2.  How do I get LyX to put the figure exactly where I want it?

Select Document→Settings.... In the Float Placement section, unset "Use Default Placement" and select "Top of Page", "Page of Floats", "Here, if possible" and "Ignore LaTeX rules". This tells LaTeX to try really hard to put the figure here first, then the top of a page, then on a page by itself. This is a global setting: all figure will then obey this rule set. If you want to control how each figure behaves, right-click in the figure float and you will get a dialog allowing to control the figure behavior.

If you really insist, you can also simply select "Here definitely". This will insert the figure by all means at the current place. Note, though, that chances are high that this leads to ugly unbalanced pages. Usually, LaTeX does a rather good job in float placement if you do not restrict it too much.

§3.  How can I restrict float placement to within a region?

Use the placeins package. Documentation can be found here.

§4.  How can I put two figures side by side?

I would like to put two floating figures side by side in Lyx as Fig 1 and Fig 2

FIG 1 : .....                     FIG 2 : ...................
  1. Insert→Float→Figure
  2. Move cursor inside Float (not Legend)
  3. Insert→Box (to insert a frameless box a.k.a. minipage)
  4. Move cursor inside Float (not Box)
  5. Insert→Formatting→Horizontal Space→Horizontal Fill or Ctrl-<space> -> right-click on space -> select "Horizontal Fill" (to insert a stretchable horizontal space)
  6. Insert→Box (to insert another minipage)
  7. Change the width of the two minipages to 45% Textwidth (by clicking the right mouse button on each minipage)
  8. In each minipage:
    • change the paragraph alignment to center
    • add the graphics
    • press enter for a new paragraph
    • Insert a caption (Insert→Caption).

See FiguresSideBySide for example files, and perhaps also BigFigureOrTable.
You can also avoid repeating all the steps with a Command Sequence. See CommandSequences

This LyxUsersThreadRoot:14093 might also be of interest, where Herbert has attached an example file in LyxUsersPost:14093 — that solution is reportedly perfect :-)

§5.  But I want the figures to be labeled 1a and 1b!

I would like to put two floating figures side by side in Lyx, but not as described in the previous question, but rather like this:

FIG 1a : .....                     FIG 1b : ...................

OK, you want subfigures. Do this:

  1. Insert→Float→Figure
  2. Again, Insert→Float→Figure (this inserts a "subfigure float" into the float)
  3. Put the cursor right next to the subfloat
  4. Insert→Formatting→Horizontal Space→Horizontal Fill or Ctrl-<space> -> right-click on space -> select "Horizontal Fill" (to insert a stretchable horizontal space)
  5. Insert→Float→Figure (this inserts another "subfigure float")
  6. In each subfloat:
    • add the graphics
    • Edit the caption

See FiguresSideBySide for example files, and perhaps also BigFigureOrTable.

This LyxUsersThreadRoot:14093 might also be of interest, where Herbert has attached an example file in LyxUsersPost:14093 — that solution is reportedly perfect :-)

Figures

§6.  How can I create a floating figure with a centered image?

Also see the question below about centering the image.

  1. Menu: Insert→Float→Figure
  2. Put the cursor in the paragraph above the line 'Figure <Nr.>'. If there's no such paragraph above, put the cursor at the start of that line and press Enter.
  3. Menu: Edit→Paragraph Settings (Layout→Paragraph) and select Center in the Alignment box. Press Ok.
  4. Menu: Insert→Graphics and choose the file etc.

The default behaviour used to be that paragraph was centered, but this was changed since it didn't match LaTeX's behaviour. If you don't like this, consider making a keyboard shortcut that centers the current paragraph, or perhaps to do all of the items above. For more details on keyboard shortcuts, see CommandSequences.

§7.  How can I center an image in a float?

Put the cursor in the paragraph with the image and open the dialog with Paragraph_Settings (Edit→Paragraph Settings...) and set the alignment of the paragraph to centered.

§8.  How do I center an image that's too big horizontally?

Inserting an image that's a little to big horizontally causes the centering mechanism to break down. The left edge gets aligned, and the right edge sticks out even more.

To fix this, do as follows:

  • Change the paragraph layout to the default (Justified).
  • Add in LaTeX mode \centerline{ before the image, and } after it.

An alternative to this which works for tables, images, and even verbatim textboxes is to:

  • add \usepackage{adjustbox} to the document's preamble
  • Change the paragraph layout to the default (Justified).
  • Add in LaTeX mode \begin{adjustbox}{center} before the image/box/etc., and \end{adjustbox} after it.

§9.  How can I put text over/on top of an image?

See PS-tricks

§10.  How can I adjust the numbering of figures?

See this FAQ section.

§11.  How can I adjust the captions of figure floats?

Example preamble command for converting eg. "Figure n:" -> "Fig. n:"

\renewcommand{\fnum@figure}{Fig.~\thefigure}

For more complicated things use caption package. Example conversion from "Figure n:" into "Figure (n)"

\usepackage{caption}
\captionsetup{labelformat=parens}

§12.  How do I convert a .ps-file to .eps?

Perhaps the best option is to use ps2eps (it is better than ps2epsi which comes with ghostscript).

§13.  How to make a Gantt chart with LyX?

If you want to create a Gantt chart in Lyx you need LaTeX-package pst-gantt (http://mirror.its.uidaho.edu/pub/tex-archive/graphics/pstricks/contrib/pst-gantt/(approve sites)) in your preamble document. As well pst-gantt loads by default the following packages: pst-node, pst-grad, xkeyval and pstricks, so all them should be already part of your local TEX installation. As pst-gantt loads pstricks package you can only export/view your document to PostScript, DVI or PDF(ps2pdf).

For example adding this TeX Code in your document you can to make a simple Gantt chart:

\newpsstyle{Important}{fillstyle=solid,fillcolor=red}
\newpsstyle{NotImportant}{fillstyle=vlines}
\begin{PstGanttChart}[unit=2,TaskOutsideLabelMaxSize=1,ChartShowIntervals]{5}{7}
\PstGanttTask[TaskOutsideLabel={Task 1}]{0}{3}
\PstGanttTask[TaskOutsideLabel={Task 2},TaskUnitType=Day]{15}{3} % 3 days starting at day 15
\PstGanttTask[TaskStyle=Important,TaskOutsideLabel={Task 3}, TaskInsideLabel={\Large\textcolor{white}{\textbf{Important}}}]{2}{5}
\PstGanttTask[TaskStyle=NotImportant,TaskOutsideLabel={Task 4}]{4}{2}
\PstGanttTask[TaskOutsideLabel={Task 5}]{5}{2}
\end{PstGanttChart}

For additional information and examples click here http://mirror.its.uidaho.edu/pub/tex-archive/graphics/pstricks/contrib/pst-gantt/pst-gantt-doc.pdf(approve sites)

§14.  How do I use figures defined with MetaPost in LyX?

Obviously you can produce EPS with mpost (figure files get the figure number as the extension, rename them to .mps) or you can produce PDF figures from MetaPost with mptopdf, or use the MetaPost converter for LyX which allows you to include .mp files directly.

§15.  How can I preserve figure locations on different computers?

You should use relative, not absolute paths. From Wikipedia: " a relative path starts from some given working directory, avoiding the need to provide the full absolute path.".

You can achieve this in two ways.

§15.1  Put everything in one folder

  1. Save your new LyX file in its own folder
  2. Save any external figure in the same folder
  3. In the LyX file, load graphics as usual.

Example directory structure:

/home/youruser/foldername/lyxfilename.lyx
/home/youruser/foldername/figure.jpg

§15.2  Manually edit path in Lyx

If you want to have your figures in a different folder then the lyx files. You can follow this procedure:

  1. In Lyx load the Graphic as usual.
  2. Manually edit the textbox in which the path of the file is shown and make the path relative.

Example directoy structure:

/home/youruser/yourproject/text/lyxfilename.lyx
/home/youruser/yourproject/graphics/name_of_figure.jpg

In the insert graphics dialogue of file lyxfilename.lyx you would enter the following path:

../graphics/name_of_figure.jpg

FAQ Figures

§16.  How can I redefine the command \listoffigures

To do this, you want to know the current definition of \listoffigures, because you probably don't know how to re-implement it. Getting this is trivial:

Start latex with no parameters (i.e. type latex<enter> in a terminal) You should get something like this, possibly a different version:

This is TeX, Version 3.14159 ([[Web2C]] 7.3.7)
**

type in \documentclass{book}<enter>
You should get another "*" prompt. Type in \show\listoffigures<enter> And there it is! Put all of it in the preamble of your document. Test it (view dvi or similiar) to see that you didn't make any mistakes cutting and pasting it.

If this works flawlessly, change the definition by putting your \addcontentsline{} somewhere in the middle of it.

If you know some latex you'll see a good spot. If not - experiment. Too early and you get the "page before" problem, too late and you'll get the "last page" problem. Look for a place in the macro after the new page/chapter has started, before the actual listing begins. Somewhere around the heading perhaps. Make sure to put your \addcontentsline between other commands, not in the middle of one.

FAQ Figures

FAQ Figures

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2016-06-14 14:31 UTC