I have to write a report for school and I need to include a UML class diagram for a Java assignment. I am using the PlantUML integration within IntelliJ to create a beautiful diagram without any whitespace around it. But when I put it into my LaTeX report I get So much white space that it's hard to read...

This is my code to include the .svg figure:

    \includesvg[width=\textwidth, inkscapelatex=false]{uml}
    \caption{Ett UML-diagram över klasserna i systemet.}


\documentclass[11pt, titlepage, oneside, a4paper]{article}

        \includesvg[width=\columnwidth, inkscapelatex=false]{uml}
        \caption{Ett UML-diagram över klasserna i systemet.}


enter image description here

This is my goal. I'm using a .png here, which is lower quality and doesn't store vectors. As you can see the image doesn't have unnecessary whitespace above the caption:

enter image description here

  • I have tried using \linewidth instead of \textwidth, but that doesn't seem to work either – cephlot Nov 17 '19 at 13:53
  • Welcome to TeX.SE! Please include a minimal working example with your question, that we can copy-paste and compile. Thank you for at least including the relevant code, though. Also consider sharing a screenshot; I'm not sure what you mean when you say you're getting so much whitespace it's hard to read. figure environments float and do insert whitespace around themselves to separate them from the text, so it may be that's your problem. Do you get unwanted whitespace when you include the figure without the figure environment? – dgoodmaniii Nov 17 '19 at 13:56
  • Added a MWE and a screenshot of the compiled .pdf. I tried compiling without the figure body, but it's the same – cephlot Nov 17 '19 at 14:43
  • This looks very easy to read and appropriately spaced to me. Where is the whitespace you want removed? – dgoodmaniii Nov 17 '19 at 16:14
  • Added another screenshot of the same page with a png instead. This version has no white space – cephlot Nov 17 '19 at 16:36

I would've added this as a comment but my reputation is too low to comment:

What I end up doing on such occasians is one of the following things:

  • Use an image editor to manually remove any unwanted whitespace before including the svg in LateX (e.g. Inkscape). Even if you think there is none take a look and verify it.
  • Use an online alternative for cleaning up your svg file (e.g. https://jakearchibald.github.io/svgomg/) even though I do not know if this exact one fulfils your purpose
  • If you can export your diagram as a cropped pdf that usually is another way to try remove the unwanted whitespace.
  • Try any other vector format which you can export to from your framework and try including that in your report.

I know that these are not the "best" solutions and there is probably a native LateX solution but I just wanted to give a little help.

  • There is no whitespace in either inkscape or svgomg unfortunately. I'll keep to the png for now. Thank you for the options though! – cephlot Nov 17 '19 at 16:49
  • If this is true I would try converting the svg to a pdf (e.g. using cloudconvert.com/svg-to-pdf) and including that into your report. Sometimes LateX doesn't handle svg files well but I found pdfs to be very reliable. On a minor note: pdf does store vectors like svgs – Robin Schmidt Nov 17 '19 at 16:52
  • That could work! Thank you! – cephlot Nov 17 '19 at 16:57
  • Another way to check the image margins is to use \fbox{\includesvg{...}}. Note it does add 2pt (\fboxsep) itself. – John Kormylo Nov 17 '19 at 23:39

I've just solved this problem for myself:

Replace \usepackage{svg} with \usepackage[inkscapearea=page]{svg}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.