0

I need to show two diagram in PNG format next to each other and I did it using the following code, but the resolution and quality of the figure is not good as it should be. I have their SVG format too, but as far as I know it is not easy to use the SVG format in latex. Is there a practical solution to use SVG? As SVG format quality is much better than PNG.

PS. I can upload SVG format of the figures here, if needed.

It is worth noting that if textwidth becomes more than 0.45, two figures are no longer inserted horizontally next to each other and this size of image causes decreasing the quality and resolution.

\begin{figure}[htbp]
    \centering
    \begin{subfigure}[b]{0.45\textwidth}
        \includegraphics[width=\textwidth]{Picture4}
        \caption{}
        \label{Picture4}
    \end{subfigure}
    \begin{subfigure}[b]{0.45\textwidth}
        \includegraphics[width=\textwidth]{Picture2}
        \caption{}
        \label{Picture2}
    \end{subfigure}
   \caption{Caption.}
\end{figure}
  • 4
    Have you took a look at https://tex.stackexchange.com/questions/122871/include-svg-images-with-the-svg-package, and especially, on this answer: https://tex.stackexchange.com/a/129854/132405 (see also the comments of this answer if you're on a Mac)? It is perhaps easier to convert the SVG to PDF with a graphic converter software if you have only few SVG files to use. – quark67 Feb 23 '23 at 05:38

1 Answers1

3

I'll just exploit/spell out what @quark67 already hinted at in their comment. If I was in your place I'd convert the .svg-files to .pdf-files and use \includegraphics then. There are many (free, online) tools for that.

I am quite sure that you can use a larger number than 0.45, but not 0.5. The reason is that the line break after the first \end{subfigure} causes a space which is inserted between the two subfigures. This means you have 0.5\linewidth + space + 0.5\linewidth, which does not fit into one line. You can prevent the space if you comment the linebreak, see code below.

The image is stolen from https://freesvg.org/3d-atom-model, I just needed an example.

enter image description here

\documentclass{article}

\usepackage{svg} % provides 'includesvg' \usepackage{subcaption} % provides 'subfigure' and corresponding caption \usepackage{showframe} % only for testing reasons, just kick it out

\begin{document}

\begin{figure}[htbp] \centering \begin{subfigure}[b]{0.5\textwidth} \includesvg[width=\textwidth]{example} \caption{Subfig 1.} \label{sfig:Picture4} \end{subfigure}% <- This will prevent adding a small space between the subfigures which causes the linebreak. \begin{subfigure}[b]{0.5\textwidth} \includesvg[width=\textwidth]{example} \caption{Subfig 2.} \label{sfig:Picture2} \end{subfigure} \caption{Caption.} \label{fig:Pictures} \end{figure}

\end{document}


Edit

As seen in the comments, the text doesn't scale together with the image. Therefore one could use \resizebox instead of the optional width argument of \includesvg, but this leads to unreadable small text. Maybe a combination of both could satisfy the requirements:

\begin{subfigure}[b]{0.5\textwidth}
   \scalebox{0.6666}{\includesvg[width=1.5\textwidth]{example}}
   \caption{Subfig 2.}
   \label{sfig:Picture2}
\end{subfigure}

Here it is necessary that the factor in \scalebox's first argument is the multiplicative inverse of the factor before \linewidth.

Obligatory note: It is not the best style to use \scaleboxes for figures containing text because this leads to nonuniform font sizes in your document. The cleanest way to go would be using TikZ.

Οὖτις
  • 2,897
  • 1
  • 5
  • 18
  • (1) In your code, is 'example' format SVG or PDF? (2) After adding use packages a border line is created in all of pages. (3) Also, the format of SVG is damaged when it is shown after compiling. My SVG is uploaded here : https://svgshare.com/i/qZu.svg – Questioner Feb 23 '23 at 11:16
  • The problem of the border is solved, it was due to frame package. But the SVG after compilation is not shown properly, it is seen in the PDF file like this : https://i.postimg.cc/bNmZ5fn2/sssssssvvvvggggg.png – Questioner Feb 23 '23 at 11:24
  • (1) It is the SVG file from the mentioned webpage. (2) This is done by \usepackage{showframe}. You can just delete it. (3) I fear I am unable to download the file. Is there a way to do that? – Οὖτις Feb 23 '23 at 11:25
  • Yes, to download my SVG file, it is enough to click on the link, where the SVG has been uploaded, and then right click and select 'Save as' from the menue. – Questioner Feb 23 '23 at 11:29
  • 1
    Thanks, got it. Looks like the text in the SVG file is not scaled, this leads to overlaps. You could work with \resizebox{Factor}{\includesvg{Image}}, but you will have to determine the correct scaling factor by hand (I think). This will also lead to unreadable text as it becomes too small. Maybe you could combine \resizebox and the optional width argument to get the correct size and readable text. – Οὖτις Feb 23 '23 at 11:35
  • 1
    @Questioner please see updated answer for a way to somehow circumvent this issue. – Οὖτις Feb 23 '23 at 11:49
  • Thanks, it's so better, but how to reduce a bit size of the numbers? – Questioner Feb 23 '23 at 12:29
  • Just play around with the factor before \linewidth and the corresponding factor of the scalebox. A larger factor before \linewidth leads to a smaller factor of the scalebox and to smaller numbers. Maybe try 2 and 0.5 for the two factors respectively. – Οὖτις Feb 23 '23 at 14:28
  • Do you mean textwidth , which is 1.5 ? Because there is no linewith in your code. Thanks – Questioner Feb 23 '23 at 23:01
  • Actually I meant to write \linewidth in my answer, but here it does not seem to make a difference (see https://tex.stackexchange.com/a/16956/237192). So you are right, you need \scalebox{1/F}{\includesvg[width=F]{example}} where F is to be replaced by some positive number and 1/F by its inverse. Larger values of F make the text smaller, smaller values make it bigger. – Οὖτις Feb 24 '23 at 12:46