Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Adding an excel graph into a LaTeX pdf.

  1. Nov 1, 2013 #1
    How do I go about doing this? I'd like the graph to be fitted to the size of the page (A4) also, not just stuck on at the end in full size.
  2. jcsd
  3. Nov 1, 2013 #2
    What have you tried?
    What's not working?

    Can you print the graph to PDF?
    Include the PDF into the latex doc?
  4. Nov 1, 2013 #3
    I can save the excel graph as a pdf. Following that, I've been able to merge the two pdfs. However, the excel graph shows up as a different size sheet at the end of the merged pdf document. I'd like it to fit on to a normal, vertical A4.
  5. Nov 1, 2013 #4

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    Some questions first:

    - What kind of graph is it: A line graph, a bar graph, a surface graph, something else?
    - Why an Excel graph? They typically aren't particularly professional looking graphs.
    - Can you export the data and use a different tool such as gnuplot to create your graph?

    If you insist on that Excel graph, put the chart on its own worksheet. Select page layout for that sheet and zero out the margins. Next you'll need to create a custom page size for your "Print as PDF" driver. You'll want a page with zero margins and whose outer size is no larger than the inner size of a page in your LaTeX document. Now go back to your Excel graph. You'll need to resize it to fit on one page. Finally, print as PDF.
  6. Nov 1, 2013 #5
    It's a scatter plot with smooth lines. Is there a more professional alternative to Excel? If so, I'd certainly be interested.
  7. Nov 1, 2013 #6
    Just saw that third my point about gnuplot. I collected the data myself, so the program I use for the graph isn't restricted to excel whatsoever.
  8. Nov 1, 2013 #7
    I thought when you include a pdf figure file into latex, you could tell it what size you want it to be and whether to preserve aspect ratio.

    As far as using a different software, there are even ways of plotting directly from within the latex document...things like PGFPlots and even ways to execute python scripts the generate a matplotlib figure, etc.
  9. Nov 1, 2013 #8


    User Avatar
    Science Advisor

    You can. Use the graphicx (note the x - that's not a typo) package and compile with pdflatex. Then \includegraphics[width=0.9\textwidth height=100pt keepaspectratio]{foo.pdf} (or similar). More here.

    Have a Google. I can post a working example in a couple of days if you can't find anything.
  10. Nov 1, 2013 #9

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    Yes, you can, but if that pdf file contains a bit-mapped graphic, resizing it to fit often looks rather lousy.
  11. Nov 1, 2013 #10
    Right, so a lot of that was pretty much gibberish to me. I literally downloaded LaTeX yesterday, having no prior knowledge of it before. I've used it got writing this current lab report and I've found it far easier to deal with, and the equations come out brilliantly. But, beyond inputting tables and lists and equations and stuff, I'm lost. Could someone give me a more simple explanation of how to produce a decent line plot, either in LaTeX or in another program that's compatible with it? Thanks for the help so far.
  12. Nov 2, 2013 #11


    User Avatar
    Science Advisor

    The first thing in a latex doc is a \documentstyle command. Add a line below it:


    You now have all the commands defined in the package graphicx available to use. One of those commands lets you include graphics files. In its simplest form it is:


    Just type it in to the body of the document, replacing foo.pdf with the filename of your graph, and recompile. The filetypes you can use depend on how you are compling your document. See the link in my last for what works with what. If your graph is a pdf file, you'll need to compile with pdflatex. If you're running latex from the command line, just type pdflatex instead of latex. If you're using MikTex, there's a dropdown that will let you choose "Latex --> PDF". If you're using something else, have a poke around.

    You can get a fair bit of control over how latex displays the pdfs. I gave an example in my last. That one shows the pdf scaled to fit within a rectangle that is 90% of the width of the text on the page and 200 points high. Try specifying one or the other or both, or leaving out the keepaspectratio.

    You will want to put the includegraphics command in a figure environment rather than just in open text:

    \includegraphics[]{} <- you fill in the brackets
    \caption{A graph!}

    Latex will put the figure somewhere sensible. You could also write the first line as


    which asks latex to try to put the figure here. Instead of h you can use t or b (top or bottom of the page). You can also add an exclamation mark to make latex try really hard to place the figure where you asked.

    Does that help?
  13. Nov 2, 2013 #12
    Thanks a million for that. Worked perfectly and got the graph looking nice and sharp.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook