10

I have this doubt

Using lyx inside a floating I been putting the images, everything was good but then I realized something: some images are aligned in the center and others not. I don't understand because I have put the latex code \centering beside every image but it seems that this doesn't work for all the images.

enter image description here

enter image description here

Do you know what could be the problem and what can I do?

Thanks a lot.

5
  • Are the images it doesn't work for very wide? \centering won't help in that case, they'll just poke out on the right anyway. The boring way of fixing it is to insert some negative horizontal space by for example writing \hspace*{-1cm} in an ERT just before the image. Another way is to use \makebox as in this answer (also with ERTs. Commented Sep 5, 2013 at 20:37
  • Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code. Many people here use LaTeX directly, so probably is better if you show the LaTeX code (View menu) or an exported MWE (File menu) from \documentclass{...} to \end{document}.
    – Fran
    Commented Sep 5, 2013 at 20:40
  • use \frame{\includegraphics{.......}} the frame will put a visible box around the image so you can see how big latex thinks it is, it may be wider than the page (in which case use [width=\textwidth] to scale it down) or it may have white space inside the frame in which case the specified bounding box for the figure is incorrect. Commented Sep 5, 2013 at 20:48
  • Thanks a lot for your replays. I have been trying to control this problem with your advices. The images I'm using are not bigger that the page, actually it seems that the problem is only with the smaller images, like if the Latex code were invisible for the editor. But then I put the image in another lyx file just to prove and.. surprise!! not problem with them in a new project. Does it have any sense?, I mean, in theory the general configuration (margins, tipography...) of the editor should have effect on all the files, or not? Commented Sep 6, 2013 at 17:56
  • Could you create a minimal example? That is, remove as much content as you can from your document while still demonstrating the problem, then edit your question to include either the .lyx file itself or the exported LaTeX source. (A .lyx file is just plain text, so if you open it in a text editor you can just copy everything.) Commented Sep 6, 2013 at 18:18

2 Answers 2

11

The captures are from a Lyx in Spanish, but the procedure must be the same in the English version, may be with different words to those that I use.

LyX method:

MWE

  1. Select with the cursor select a block of text iside the figure float but without text, including just the image (when done, you will see a cyan border around the image)
  2. Right mouse click.
  3. Select "Paragraph configuration" (or something with this meaning)
  4. Select the radio button "Center"
  5. Apply or Accept

ERT method:

MWE2

  1. Put the cursor just before the image, but inside of the figure float
  2. Insert a ERT box (Ctrl+L)
  3. Write \centering

You will see the image still in the left side but will be centered in the PDF:

7
  • While I applaud you taking the time to write such a detailed answer, this really is just repeating exactly what has been said before. And regarding your final note, I think you're mixing center and centering. (Sorry if I sound like a grumpy old guy, that is not my intention.) Commented Sep 13, 2013 at 21:13
  • One more answer stating the same, now with illustration.
    – juliohm
    Commented Sep 13, 2013 at 21:14
  • @TorbjørnT. Lyx 2.0.5.1 write \begin{centering}, not \begin{center}, in the float. With respect to the answer, yes is the same. I started without see any answer, and I spent time making screenshots, draft and was doing other things too. I saw the others answers afer saving. That's it. If you want include the screenshots in your answer (or your own images, of course) I will delete this answer.
    – Fran
    Commented Sep 13, 2013 at 21:39
  • Wrt. to center vs. centering: I know what LyX does. As far as I know there isn't really any centering environment though, and it is center that adds vertical space, see e.g. tex.stackexchange.com/a/23653/586. (It works because LaTeX is created so that commands may work as environments, even if that is not always recommended, see e.g. this comment by David Carlisle. Oh, and I'm too lazy, so I'll just delete my answer insted. Commented Sep 14, 2013 at 8:12
  • @TorbjørnT. You should not delete your answer, please restore it. With respect to centering environment, after all, it works, then exists. :-). Well seriously, you're absolutely right. If I remember correctly, long ago Lyx really added this vertical space (so, using center), but usually I write only plain LaTeX using \centering inside floats, hence my confusion.
    – Fran
    Commented Sep 14, 2013 at 10:15
0

You rarely need to insert TeX directly in LyX documents, and in fact using \centering here is inadequate.

For alignment of figures, simply right-click the paragraph where the picture is and select Paragraph settings... Choose the alignment and you're done.

3
  • 1
    How is it inadequate? (And by the way, I mentioned the paragraph setting in my answer as well.) Commented Sep 13, 2013 at 20:42
  • @TorbjørnT.: Sorry, I didn't read your answer entirely. It's inadequate because LyX provides the Paragraph interface that should be used instead. I like to think of TeX insertion in LyX as a hack for problems that can't be handled in the current version. More LyX evolves, less TeX inlines in the document.
    – juliohm
    Commented Sep 13, 2013 at 20:50
  • I do sort of agree that if things can be handled (easily) via the LyX GUI, then that is the best way to do it, but I'm not sure 'inadequate' is the right word to use, at least with my understanding of it. Also, LyX adds centering as an environment inside figures, which it isn't intended as, AFAIK. Commented Sep 13, 2013 at 20:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .