How to quickly insert a figure in LyX
By Dmitry Kabanov
I will show one of the user-defined commands that I use in Lyx, a \(\LaTeX\) frontend, to quickly insert figures with captions.
Lyx is a wonderful software that makes it easier to typeset documents that are usually produced with \(\LaTeX\). Instead of seeing only \(\LaTeX\) source code, you can see approximately what the final document will look like. Particularly, the typesetting of mathematical formulas is much easier, as you can see their rendered form immediately. I used Lyx a lot during my PhD years, and I still use it often for private writing, such as small mathematical notes or laboratory notebooks.
When you use some software extensively, you do some operations very frequently. One of such operations is to insert figures. The procedure is the following:
- You press the
Insert float
toolbar button or the corresponding menu command. - Then you need to remove the end-of-paragraph symbol after the caption placeholder. (I am not quite sure why it is there.)
- Move the cursor to the paragraph up, where the figure will be inserted.
- Open
Paragraph settings
dialog window. - Set property
Centered
. - Close the dialog window.
- Open the dialog window for the figure using the
Insert graphics
toolbar button or the corresponding menu item.
Only after these generic actions, you start to do something unique, like choosing the actual graphics file you want to insert or typing the figure caption.
To make the process simpler, it is helpful to introduce a new command that will do the above actions for you and assign a keyboard shortcut for this command. The process is the following.
-
Open Lyx Preferences (it depends on the operating system that you use).
-
Click the
New
button. -
In the opened
Edit shortcut
window, insert the following line in theFunction
field:command-sequence float-insert figure; char-right; char-delete-forward; up; paragraph-params \align center; dialog-show-new-inset graphics;
-
In the
Shortcut
field, choose your shortcut (my preference isCtrl-Shift-F
). -
Press
OK
.
That’s it! Now it will be much easier to insert new figures in Lyx documents. By pressing the chosen shortcut, you are immediately taken to the dialog window for selecting a graphic file, and after selecting it, you have it centered. The only thing left is to type the corresponding figure caption.