Adding an excel graph into a LaTeX pdf.

In summary, you can export the data from Excel and use a different software to create a graph, or put the graph on its own worksheet and resize it to fit on one page.
  • #1
SherlockOhms
310
0
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.
 
Physics news on Phys.org
  • #2
What have you tried?
What's not working?

Can you print the graph to PDF?
Include the PDF into the latex doc?
 
  • #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.
 
  • #4
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.
 
  • #5
It's a scatter plot with smooth lines. Is there a more professional alternative to Excel? If so, I'd certainly be interested.
 
  • #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.
 
  • #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.
 
  • #8
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.
 
  • #9
gsal said:
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.
Yes, you can, but if that pdf file contains a bit-mapped graphic, resizing it to fit often looks rather lousy.
 
  • #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.
 
  • #11
The first thing in a latex doc is a \documentstyle command. Add a line below it:

\usepackage{graphicx}

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

\includegraphics{foo.pdf}

Just type it into 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:

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

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

\begin{figure}[h]

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?
 
  • #12
Thanks a million for that. Worked perfectly and got the graph looking nice and sharp.
 

1. How do I add an Excel graph into a LaTeX PDF?

To add an Excel graph into a LaTeX PDF, you will need to first save your graph as an image file, such as a JPEG or PNG. Then, in your LaTeX document, use the \includegraphics command to insert the image at the desired location. Make sure to also include the graphicx package in your document's preamble.

2. Can I edit the Excel graph after inserting it into my LaTeX PDF?

No, once you have saved your Excel graph as an image file and inserted it into your LaTeX document, it cannot be edited. Any changes to the graph will need to be made in the original Excel file, followed by re-saving the graph as an image and re-inserting it into the LaTeX document.

3. How can I ensure that the Excel graph appears clearly in my LaTeX PDF?

To ensure that the Excel graph appears clearly in your LaTeX PDF, make sure to save the graph as a high-quality image with a resolution of at least 300 DPI. You can also adjust the size and position of the graph in your LaTeX document to better fit the page.

4. Can I add multiple Excel graphs into one LaTeX PDF?

Yes, you can add multiple Excel graphs into one LaTeX PDF by saving each graph as a separate image file and inserting them into your document using the \includegraphics command. You can also use LaTeX's subfigure or subcaption packages to arrange the graphs side by side.

5. Is there a way to automatically update the Excel graph in my LaTeX PDF?

If you make changes to the Excel graph after inserting it into your LaTeX document, you will need to save the updated graph as a new image file and re-insert it into the PDF. However, there are some LaTeX packages, such as exceltex, that allow for automatic updates of Excel graphs in a LaTeX document, but they may require additional setup and coding.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
955
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
113
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
376
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
734
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top