LyX is a lovely bit of software for preparing beautiful documents – you get the high quality output of LaTeX and the advantages of logical document description in a usable interface and without having to remember TeX syntax. There are a few aspects of using LyX that puzzled me while writing a certain large document, however – many of these are dealt with in the LyX FAQ, but I thought it would be worth collecting those that were most useful to me here.
Use pdflatex for Output
There are various different options for generating output PDF output in LyX, but it will save you trouble if you do everything using pdflatex in the first place. (I think this is the upshot of the slightly unclear advice in the FAQ on the subject.) This turned out to be particularly important because when your document is 50000 words long and has over 100 figures, the other methods take over 10 minutes to generate a PDF; pdflatex would finish in a couple of seconds. If you take this advice then you have to change the Document -> Settings -> Document Class option to pdfTeX, or you get some surprising errors. Also, I would strongly recommend that you only use PNG files for bitmap images and PDF for vector graphics. (PNG is obviously sensible, but in the case of vector graphics I found PS and EPS files unexpectedly awkward in terms of getting the orientation and clipping right.)
Incorrect Colours in Bitmap Graphics
I came across a bizarre problem where the colours would be slightly wrong for certain PNG files that I include in the document. (I suppose I should say “colors” too, just for the sake of searchers using American English.) This turned out to be a problem with full-colour PNG images with transparency (i.e. RGBA images), which my notes say is discussed further in these posts. Setting the PDF version as suggested in the first of those posts didn’t help me at all, so I had to convert all my RGBA PNG files to RGB. If you want to check for these files you can use file(1), something like:
find . -type f -iname '*.png' -print0 | xargs -n 1 -0 file | egrep RGBA
… and I fixed them by feeding the filenames (one per line) to a script like:
#!/bin/sh set -e while [ $# -ne 0 ] do t=`mktemp` convert "$1" png24:"$t" && mv "$t" "$1" shift done
Obviously you need imagemagick installed for the “convert” command.
Footnotes
By default there is no extra vertical space to separate footnotes, but I much prefer there to be a small gap. To do that, add to the following line to the document preamble:
\setlength{\footnotesep}{12pt}
Captions
By default, the formatting of caption text in floated figures looks very similar to the main body text. Somewhere on the web I found the recommendation to use the “caption” package to change this, e.g. by adding the following to the preamble:
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=endash]{caption}
Fitting Tables Onto Pages
Making tables fit on the page is annoying – just changing the text size often doesn’t reduce the overall size or causes a horrible font to be used. Resizing the whole table is the best way I found. Before the table (either in a float or in the normal flow of the document) I added the following in ERT:
\resizebox{\textwidth}{!}{%
and then immediately after the table added, again in ERT:
}
This scales the table such that the width of the table fits the page width.
Suppressing Pages Numbers For Full Page Figures
If you want to use a whole page for a floated figure, the page number can overlap with the figure or just look odd. However, second tip here: http://wiki.lyx.org/FAQ/UnfloatingFigureOnEmptyPage works well to remove page numbers from all-page figures. To summarize, add the following to the preamble:
\usepackage{floatpag}
\floatpagestyle{plain} % Default page style for pages with only floats
Then, in ERT before the figure (but still in the float) add:
\thisfloatpagestyle{empty}
\vspace{-\headsep}
… and similarly, after the figure but above the caption add:
\vspace{0.3cm}
… or you may find the caption too close to the graphics.
Better On-Screen Fonts in PDFs
As explained in the second question in this mini-FAQ on generating PDFs from LyX you should use the outline font version of Computer Modern instead of the bitmapped versions. For me, this boiled down to going to Document -> Settings -> Fonts and setting the Roman font option to “AE (Almost European)”.
You can further improve the rendering of text in your output by using microtype. Just add
\usepackage{microtype}
… to the preamble. (These suggestions only apply if you’re using the pdflatex workflow as suggested above.)
Adding Footnotes in Tables
You might notice that adding footnotes in table cells doesn’t work. One answer to this is manually add them in ERT with \footnotemark and \footnotetext, possibly adjusting the counter as described in that FAQ entry.
Hi Mark,
did you by chance encounter the problem that the font size (Times New Roman, 12 pt, Normal) was smaller than 12 pt in the pdf output? If yes, could you find a way to solve it?
Thanks,
Diana
Diana,
Sorry, I’m afraid I hadn’t come across that problem.
I had various problems with the sizes of margins not being right, even though I entered them carefully in LyX, but I think that those turned out to be caused by me selecting options in Acrobat Reader’s print dialog that caused the page to be scaled when printing.
Hope you manage to find a solution somewhere
Fitting Tables Onto Pages
Hi Mark,
Im using your command to make tables as wide as the text width, but the command has the unwanted effect of scaling the text size up too :-S
It does not work to set the text size to normal either… Do you know the magic trick?
Magnus
Let me just add: I am trying to make a quite narrow table stretch to fit the width of the text. Preferably with evenly sized columns.. The table is not too big, a problem that your code seems to be written to cope with. If you have any suggestions, they are very welcome.
Magnus
Sorry, I’m afraid I’m not sure – I’ve always wanted the text-scaling effect, personally.
Please help me, paragraph jistify not work and paragraph text out of right margin. Page size A4, Lyx 1.6, and MikTex 2.8
Sorry, I’m afraid this isn’t a good place to ask for general questions like this – you’ll have better luck trying one of the LyX mailing lists or web forums:
http://www.lyx.org/MailingLists
Actually Google will return the same results whether you searched for “colour” or “color”, so there’s no need to include both spellings. It even corrects for common mis-spellings.