svg
svg copied to clipboard
Text scaling issues
I cannot really get text to correctly align with the image. I am guessing because the image is heavily scaled down. I tried using pretex=\tiny
and pretex=\relscale{0.1}
but it is still off (text too large).
I am thinking that maybe a solution would be if:
- Inkscape is used to convert to PDF + LaTeX.
- pdflatex is used on empty LaTeX document with just including that PDF + LaTeX to generate a new PDF file, but with LaTeX fonts.
- I then include that PDF file into my main document, scaling it as necessary.
That would make it use the LaTeX fonts but allow precise scaling as needed.
It looks like this package could support that but it is not yet fully possible? So svg-extract
could extract to a separate PDF with custom preamble in extractpreamble
, but then I think that instead of the original image the extracted PDF should be included in the main document.
If I get you right you are trying to extract a large picture, where the text actually is in the right size but the resulting image has to be scaled down for inclusion in the document, right? Well, currently not an easy task but could be done with something like
\documentclass{scrartcl}
\ifpdftex{
\usepackage[T1]{fontenc}
}{
\usepackage{fontspec}
}
\usepackage{svg}
\usepackage{svg-extract}
\begin{document}
\section*{This is a test}
\begin{figure}
\centering
\includesvg[%
exclude,
extractpath=basedir,extractname=filename,%
pretex=\Huge,
extractwidth=50cm
]{svg-example}
\IfFileExists{svg-example_svg-tex-extract.pdf}{%
\includegraphics[width=\textwidth]{svg-example_svg-tex-extract.pdf}%
}{}
\end{figure}
\end{document}
As you can see, this is a combination of using \includesvg
for extraction and \includegraphics
afterwards.
I will try to create a new command \includesvgextracted
but this will probably will last some time as I have to think about how this could be implemented regarding for example the handling of passed parameters, extracted file type and more.
Awesome!
Just to give you an example which was tricky: pipeline-test.zip
I solved it like this:
\begin{figure}[ht]
\centering
\includesvg[inkscapelatex=false, scale=0.6, keepaspectratio]{plot/number_trip_week_day.svg}
\caption{caption}
\end{figure}
I think this works when image is not really really huge.
Before:
After (inkscapelatex=false):
Try with an example I attached above.
With the example I obtain this:
\documentclass{scrartcl}
\ifpdftex{
\usepackage[T1]{fontenc}
}{
\usepackage{fontspec}
}
\usepackage{svg}
\usepackage{svg-extract}
\begin{document}
\section*{This is a test}
\begin{figure}
\centering
\includesvg[inkscapelatex=false, scale=0.13]{pipeline-test.svg}
\caption{}
\end{figure}
\end{document}


Oh, yes, but with inkscapelatex=false
then one cannot enter math formulas and stuff for text, no?
I have never tried with math formulas
I mean, this is the mean reason why to use this package, no? Otherwise I can just export SVG to PDF myself and embed it as PDF into my LaTeX document? If I understand correctly, setting inkscapelatex=false
does that?
I mean, this is the mean reason why to use this package, no? Otherwise I can just export SVG to PDF myself and embed it as PDF into my LaTeX document? If I understand correctly, setting
inkscapelatex=false
does that?
On the whole, yes, but with a few little things added (like the path search or the automatic invocation of the Inkscape export after an update of the SVG file).
I have a problem that seems related to this issue.
If i include a SVG using the option inkscapelatex=false
the chart looks like this:
If i use pretex=\relscale{0.55}
instead, the result looks more or less okay, but the title of the chart is far too small and moved to the left ...?
If i completely remove the pretex option the font is way too large:
I guess for now i just use the inkscapelatex=false
, but it's not perfect, because the font type doesn't match with the rest of the document.
If you got other ideas please tell me
@major-mayer Your title is probably not centered. It's actually the text-anchor css property that has to be set to middle on the parent xml element. There is actually an inkscape export bug related to this: https://gitlab.com/inkscape/inkscape/-/issues/1170
Long story short: open the svg in inkscape, press "T" to enter text edit mode, click on your title, then in the toolbar, select the "center" option. Do not select text while doing so, or it will set the alignment to the wrong xml element, and it will get ignored during export.
You'll see a small square box in inkscape, positioned at the middle of your text box. That is the anchor, text will be centered around it. Move the title around to the desired position.
Regarding the font size, you can probably prefix it with \large in the svg, though I haven't tried it.
Thanks @MayeulC for the info. There was a similar bug report on tex.se some weeks ago. I will place the appropriate notices in both places.
Let me give my two cents regarding this: The main advantage of using inkscapelatex
(besides being able to use macros and format math) is that the text font and size in the image will match the rest of the document. If \tiny
text is still too large for the image, this is a sign that the image needs to be reworked, as \tiny
is already too small to be easily readable. I regard the fact that it is non-trivial to realize microscopic text to be a feature, not a bug. (This, by the way, is not really a feature of the svg
package but of LaTeX itself. All the methods to realize those font sizes that work in the rest of the document still work with svg
.)
Thus, I would vote against including somethign like \includesvgextracted
in this package. Hacks like this are not good practice and should thus not be encouraged. If someone really wants to use it, they can explicitely introduce the hack in their document.
Now, the fact that many people are confused about how text in the svg
file translates to the typeset text in their document may suggest that this should be documented in a more visible manner by incorporating the relevant information from svg-inkscape
(which is already linked to from the documentation). Or maybe just referencing it more explicitly ("for a detailed description of how text in the svg
file translates to text in the typeset document see there") would be enough?
I totally agree with you there. I will place a clear notice at the beginning of the documentation for the next release. I had already started working on v2.03
a long time ago. Due to lack of time, however, the work has come to a complete standstill and at the moment I cannot make any reliable statement as to when I will be able to continue working on it.