web-dev-qa-db-fra.com

Inclure SVG dans LaTeX

Je veux inclure un fichier svg dans un document LaTeX.

a.svg (donné)

given.svg

a.pdf (objectif)

goal.pdf J'ai créé le tableau avec OpenOffice, je l'ai exporté dans un fichier pdf, je l'ai ensuite importé dans inkscape et je l'ai enregistré en tant que fichier svg.

Ce que j'ai essayé

Inclure svg directement

J'ai essayé d'inclure le fichier svg donné directement en utilisant le paquet svg :

\usepackage{svg}
...
\includesvg{img/a}

Mais il n'a pas été compilé, car pdflatex n'a pas trouvé le fichier a. J'ai aussi essayé a.svg mais sans succès :(

Exporter au format PDF "à la volée"

J. Engelen J'ai essayé de générer le fichier pdf à l'aide de pdflatex avec -enable-write18 ou --Shell-escape mais il n'a rien fait avec le fichier .svg sauf en lançant une erreur, que le Le fichier .pdf_tex est manquant.

Exportez en pdf/pdf_tex avant d'inclure

J'ai exporté le fichier svg en utilisant inkscape v. 0.92:

inkscape -D -z --file = a.svg --export-pdf = a.pdf --export-latex

J'ai obtenu un fichier .pdf contenant le tableau vierge: raw pdf file Et un fichier .pdf_tex contenant les éléments suivants:

%% Creator: Inkscape inkscape 0.92.1, www.inkscape.org
%% PDF/EPS/PS + LaTeX output extension by Johan Engelen, 2010
%% Accompanies image file 'RLE1.pdf' (pdf, eps, ps)
%%
%% To include the image in your LaTeX document, write
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics{<filename>.pdf}
%% To scale the image, write
%%   \def\svgwidth{<desired width>}
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics[width=<desired width>]{<filename>.pdf}
%%
%% Images with a different path to the parent latex file can
%% be accessed with the `import' package (which may need to be
%% installed) using
%%   \usepackage{import}
%% in the preamble, and then including the image with
%%   \import{<path to file>}{<filename>.pdf_tex}
%% Alternatively, one can specify
%%   \graphicspath{{<path to file>/}}
%% 
%% For more information, please see info/svg-inkscape on CTAN:
%%   http://tug.ctan.org/tex-archive/info/svg-inkscape
%%
\begingroup%
  \makeatletter%
  \providecommand\color[2][]{%
    \errmessage{(Inkscape) Color is used for the text in Inkscape, but the package 'color.sty' is not loaded}%
    \renewcommand\color[2][]{}%
  }%
  \providecommand\transparent[1]{%
    \errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package 'transparent.sty' is not loaded}%
    \renewcommand\transparent[1]{}%
  }%
  \providecommand\rotatebox[2]{#2}%
  \ifx\svgwidth\undefined%
    \setlength{\unitlength}{608.85768187bp}%
    \ifx\svgscale\undefined%
      \relax%
    \else%
      \setlength{\unitlength}{\unitlength * \real{\svgscale}}%
    \fi%
  \else%
    \setlength{\unitlength}{\svgwidth}%
  \fi%
  \global\let\svgwidth\undefined%
  \global\let\svgscale\undefined%
  \makeatother%
  \begin{picture}(1,0.13941476)%
    \put(0.12815803,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{352}}}%
    \put(0.18117534,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{320}}}%
    \put(0.23419265,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{288}}}%
    \put(0.28720997,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{256}}}%
    \put(0.34027656,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{224}}}%
    \put(0.39329387,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{192}}}%
    \put(0.44631119,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{160}}}%
    \put(0.4993285,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{128}}}%
    \put(0.56160906,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{96}}}%
    \put(0.61462638,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{64}}}%
    \put(0.66767654,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{32}}}%
    \put(0.7299571,0.12595718){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0}}}%
    \put(0.12007732,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.17309463,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.22611195,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x3}}}%
    \put(0.27912926,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x2}}}%
    \put(0.33214658,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x2}}}%
    \put(0.38521317,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.43823048,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.49124779,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.54426511,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.59728242,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.65033259,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.7033499,0.10191216){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.39329387,0.03056543){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{192}}}%
    \put(0.44631119,0.03056543){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{160}}}%
    \put(0.4993285,0.03056543){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{128}}}%
    \put(0.56160906,0.03056543){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{96}}}%
    \put(0.61462638,0.03056543){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{64}}}%
    \put(0.66767654,0.03056543){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{32}}}%
    \put(0.7299571,0.03056543){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0}}}%
    \put(0.33214658,0.00652041){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{\textit{0}\textit{x}\textit{2}}}}%
    \put(0.38521317,0.00652041){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.43823048,0.00652041){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{\textit{0}\textit{x}\textit{1}}}}%
    \put(0.49124779,0.00652041){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x3}}}%
    \put(0.54426511,0.00652041){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{\textit{0}\textit{x}\textit{2}}}}%
    \put(0.59728242,0.00652041){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x2}}}%
    \put(0.65033259,0.00652041){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{\textit{0}\textit{x}\textit{7}}}}%
    \put(0.7033499,0.00652041){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{0x1}}}%
    \put(0.04755463,0.10270052){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{…}}}%
    \put(0.15358269,0.00730877){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{…}}}%
    \put(0.82929066,0.10210925){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{unkomprimierte Daten}}}%
    \put(0.90260828,0.05441337){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{RleCompress}}}%
    \put(0.84821134,0.0067175){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{komprimierte Daten}}}%
    \put(0,0){\includegraphics[width=\unitlength,page=44]{img/a.pdf}}%
  \end{picture}%
\endgroup%

J'ai utilisé ce fichier dans LaTeX comme suit:

\begin{figure}
    \centering
    \def\svgwidth{\textwidth}
    \input{a.pdf_tex}    
\end{figure}

Le fichier .pdf résultant de mon fichier LaTeX ressemble à ça: result.pdf

Comme on peut le voir, le style de police en italique est tout, exporté par Inkscape. La couleur de police n'est pas du tout exportée.

La taille de police LaTeX des valeurs d'index doit être \tiny. Bien sûr, je peux changer le style de police manuellement, mais cela ne me semble pas être un bon moyen.

En outre, les zones autour des valeurs d'index se comportent comme suit, lorsque j'essaie de les redimensionner à l'aide de \tiny: Strange box alignment

Quelqu'un sait-il comment importer correctement des fichiers svg, contenant du texte dans un document LaTeX tout en préservant tous les styles et couleurs de police et bien sûr le positionnement?

Cordialement

9
Hymir

Étrange, l'approche que vous avez utilisée fonctionne parfaitement pour moi, mais j'obtiens un fichier pdf_tex différent de la conversion.

b.pdf_tex

%% Creator: Inkscape inkscape 0.92.1, www.inkscape.org
%% PDF/EPS/PS + LaTeX output extension by Johan Engelen, 2010
%% Accompanies image file 'b.pdf' (pdf, eps, ps)
%%
%% To include the image in your LaTeX document, write
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics{<filename>.pdf}
%% To scale the image, write
%%   \def\svgwidth{<desired width>}
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics[width=<desired width>]{<filename>.pdf}
%%
%% Images with a different path to the parent latex file can
%% be accessed with the `import' package (which may need to be
%% installed) using
%%   \usepackage{import}
%% in the preamble, and then including the image with
%%   \import{<path to file>}{<filename>.pdf_tex}
%% Alternatively, one can specify
%%   \graphicspath{{<path to file>/}}
%% 
%% For more information, please see info/svg-inkscape on CTAN:
%%   http://tug.ctan.org/tex-archive/info/svg-inkscape
%%
\begingroup%
  \makeatletter%
  \providecommand\color[2][]{%
    \errmessage{(Inkscape) Color is used for the text in Inkscape, but the package 'color.sty' is not loaded}%
    \renewcommand\color[2][]{}%
  }%
  \providecommand\transparent[1]{%
    \errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package 'transparent.sty' is not loaded}%
   \renewcommand\transparent[1]{}%
  }%
  \providecommand\rotatebox[2]{#2}%
  \ifx\svgwidth\undefined%
    \setlength{\unitlength}{798bp}%
    \ifx\svgscale\undefined%
      \relax%
    \else%
      \setlength{\unitlength}{\unitlength * \real{\svgscale}}%
    \fi%
  \else%
    \setlength{\unitlength}{\svgwidth}%
  \fi%
  \global\let\svgwidth\undefined%
  \global\let\svgscale\undefined%
  \makeatother%
  \begin{picture}(1,0.23026316)%
    \put(0,0){\includegraphics[width=\unitlength,page=1]{b.pdf}}%
  \end{picture}%
\endgroup%

test.tex

\documentclass[10pt]{scrreprt}

\usepackage{graphicx}
\usepackage[T1]{fontenc}

\begin{document}

\begin{figure}
    \centering
    \def\svgwidth{\columnwidth}
    \input{b.pdf_tex}
\end{figure}

\end{document}

Il en résulte: working example

Ma version d'Inkscape est

Inkscape 0.92.1 r

pdfTeX 3.14159265-2.6-1.40.17 (TeX Live 2016/Arch Linux) kpathsea version 6.2.2

2
vonAlenberg