Adding an excel graph into a LaTeX pdf.

Click For Summary

Discussion Overview

The discussion revolves around the process of incorporating an Excel graph into a LaTeX PDF document, with a focus on ensuring the graph fits the A4 page size. Participants explore various methods, tools, and techniques for achieving this integration effectively.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant inquires about how to fit an Excel graph to an A4 page in a LaTeX document.
  • Another asks what methods have been attempted and suggests printing the graph to PDF and including it in the LaTeX document.
  • A participant mentions successfully merging PDFs but facing issues with the graph size in the final document.
  • Questions are raised regarding the type of graph and the choice of Excel, with suggestions to use alternative tools like gnuplot for potentially better results.
  • Some participants discuss the ability to specify the size and aspect ratio when including PDF figures in LaTeX.
  • One participant expresses confusion about LaTeX and requests a simpler explanation for creating line plots.
  • Another provides detailed instructions on using the graphicx package in LaTeX to include graphics, including examples of commands and environments.
  • A later reply confirms that the provided instructions worked well for them, resulting in a sharp graph.

Areas of Agreement / Disagreement

Participants express a range of views on the best methods for including graphs in LaTeX, with some advocating for Excel while others suggest alternative software. There is no clear consensus on the most effective approach, and the discussion includes both technical guidance and personal experiences.

Contextual Notes

Some participants note limitations in their understanding of LaTeX and the technical details involved in including graphics, indicating a need for clearer explanations and guidance.

Who May Find This Useful

This discussion may be useful for individuals new to LaTeX who are looking to integrate graphs into their documents, as well as those seeking alternatives to Excel for graph creation.

SherlockOhms
Messages
309
Reaction score
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
What have you tried?
What's not working?

Can you print the graph to PDF?
Include the PDF into the latex doc?
 
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.
 
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.
 
It's a scatter plot with smooth lines. Is there a more professional alternative to Excel? If so, I'd certainly be interested.
 
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.
 
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.
 
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.
 
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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K