[Tex/LaTex] Problem inserting pages from a PDF into a Lyx document


I want to insert one page from a PDF file into my Lyx presentation file. I use Insert–>File–>External, PDFPages, select the PDF file, then I go to Options and type 'pages={1}' to select the first page from the PDF.

The result looks like a jumbled overlaid mess of all 7 pages of the PDF. This jumbled image does not show up at all in a compiled pdflatex output file. And it also causes an error when I try to preview the file by hitting command-t; the error reads "LaTex Error: File `' not found."

I am new to Beamer in Lyx (though not entirely new to Lyx), I might be missing something basic. Do I need to install a package or something?

Thank you for your help.

Best Answer

I'm not very familiar with beamer presentations in LyX, but I will quote a passage from the beamer manual, page 18-19 (emphasis mine):


Commands like \includepdf only work outside frames as they produce pages “by themselves.” You may also wish to say

\setbeamercolor{background canvas}{bg=}

when you use such a command since the background (even a white background) will otherwise be printed over the image you try to include. Example:

\setbeamercolor{background canvas}{bg=}
A normal frame.

LyX doesn't use \begin{frame}/\end{frame}, it defines some custom commands instead (\lyxframe/\lyxframeend), but the same point applies I would guess: the \includepdf cannot be inside a frame, so you have to place after a \lyxframeend (EndFrame from the style menu), before the next \lyxframe (BeginFrame from the style menu).

The second point requires an ERT. Create one with Ctrl + L (or Insert --> TeX code) just before the inserted PDF, and write

{\setbeamercolor{background canvas}{bg=}

in it. Add a second ERT just after, and add a closing brace, }, in this. This is probably why the PDF didn't appear, because it is covered by the background colour. The braces are necessary to keep the redefinition of the background colour to that single slide.

Possible alternative, \includegraphics

Depending on what you're after, you can perhaps use the standard Insert --> Graphics to insert the page. In the LaTeX and LyX options you can add page=5 to insert page number 5 of the PDF. As this is inserted as an image, the header, footer etc. of your presentation will be visible.