在 Inkscape 中绘制的 SVG 无法在带有 svg 包的 overleaf 中使用

在 Inkscape 中绘制的 SVG 无法在带有 svg 包的 overleaf 中使用

我在本地使用 Inkscape 创建了一个 SVG 绘图。然后我将创建的文件上传到 overleaf 并希望将其包含在内。我使用之前使用过的 svg 文件验证了正确的设置。

svg 不起作用

\begin{figure}[htpb]
    \centering
    \includesvg{figures/Zeichnung.svg}
    \caption{Borken svg}
    \label{fig:Broken}
\end{figure}

正确工作的 svg

\begin{figure}[htpb]
\centering
\includesvg[width=0.55\textwidth]{figures/Definition_Viskositaet.svg}
\caption{working svg file}
\label{fig:Viskosität}
\end{figure}

结果

在此处输入图片描述

Overleaf 给了我这个错误信息:

See the svg package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.5     \includesvg{figures/Zeichnung.svg}
                                          
Did you run the export with Inkscape? There's no file
`./svg-inkscape/Zeichnung_svg-tex.pdf_tex'
although `figures/Zeichnung.svg' was found.

我找不到指定的文件,但它显然可以与其他 svg 文件一起使用,因此没有出现任何错误。

我认为我用 Inkscape 生成的文件无法与 SVG 包一起使用。但是,我不知道如何修复这个问题,也不知道如何创建我自己的 SVG 以便在 overleaf 中使用。需要澄清的是,我用来测试设置的 SVG 来自在线来源,因此不是我自己创建的。

答案1

这是 Inkscape pdf 导出(由该包使用svg)中的一个已知错误,请参阅https://gitlab.com/inkscape/inkscape/-/issues/1984。此问题已在 Inkscape 中修复(请参阅https://gitlab.com/marcjeanmougin/inkscape/-/commit/9b5de7815fcd93c2801c7fb8703491125ef906b5) 因此在某些时候这可能会被 Overleaf 接收并且 svg 将正确呈现。

同时,错误报告还提供了一种解决方法:将context-strokeSVG 源中的所有实例替换为固定颜色,例如#000000(黑色)。您的 SVG 中有八个实例。我将它们替换如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
 
<svg
   width="125.33871mm"
   height="17.948942mm"
   viewBox="0 0 125.33871 17.948942"
   version="1.1"
   id="SVGRoot"
   sodipodi:docname="Zeichnung.svg"
   inkscape:version="1.1.2 (b8e25be833, 2022-02-05)"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg">
  <sodipodi:namedview
     id="namedview108087"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageshadow="2"
     inkscape:pageopacity="0.0"
     inkscape:pagecheckerboard="0"
     inkscape:document-units="mm"
     showgrid="false"
     inkscape:zoom="0.64052329"
     inkscape:cx="239.6478"
     inkscape:cy="81.964233"
     inkscape:window-width="1264"
     inkscape:window-height="664"
     inkscape:window-x="1993"
     inkscape:window-y="260"
     inkscape:window-maximized="0"
     inkscape:current-layer="layer1" />
  <defs
     id="defs108082">
    <linearGradient
       inkscape:collect="always"
       xlink:href="#linearGradient41534"
       id="linearGradient104483"
       x1="326.86093"
       y1="76.218559"
       x2="369.78787"
       y2="76.218559"
       gradientUnits="userSpaceOnUse" />
    <linearGradient
       inkscape:collect="always"
       id="linearGradient41534">
      <stop
         style="stop-color:#0b30f6;stop-opacity:0.69999999"
         offset="0"
         id="stop41530" />
      <stop
         style="stop-color:#ff001c;stop-opacity:0.70194983"
         offset="1"
         id="stop41532" />
    </linearGradient>
    <linearGradient
       inkscape:collect="always"
       xlink:href="#linearGradient38240"
       id="linearGradient38242"
       x1="270.06329"
       y1="108.74166"
       x2="368.96173"
       y2="108.74166"
       gradientUnits="userSpaceOnUse"
       gradientTransform="matrix(0.43405083,0,0,0.43405083,209.63973,29.019152)" />
    <linearGradient
       id="linearGradient38240"
       inkscape:swatch="solid">
      <stop
         style="stop-color:#002bff;stop-opacity:1;"
         offset="0"
         id="stop38238" />
    </linearGradient>
    <marker
       style="overflow:visible"
       id="Arrow1Sstart-8"
       refX="0"
       refY="0"
       orient="auto"
       inkscape:stockid="Arrow1Sstart"
       inkscape:isstock="true">
      <path
         transform="matrix(0.2,0,0,0.2,1.2,0)"
         style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:1pt"
         d="M 0,0 5,-5 -12.5,0 5,5 Z"
         id="path68676-4" />
    </marker>
    <marker
       style="overflow:visible"
       id="Arrow2Send"
       refX="0"
       refY="0"
       orient="auto"
       inkscape:stockid="Arrow2Send"
       inkscape:isstock="true">
      <path
         transform="matrix(-0.3,0,0,-0.3,0.69,0)"
         d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
         style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round"
         id="path68697" />
    </marker>
    <marker
       style="overflow:visible"
       id="Arrow1Sstart-8-0"
       refX="0"
       refY="0"
       orient="auto"
       inkscape:stockid="Arrow1Sstart"
       inkscape:isstock="true">
      <path
         transform="matrix(0.2,0,0,0.2,1.2,0)"
         style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:1pt"
         d="M 0,0 5,-5 -12.5,0 5,5 Z"
         id="path68676-4-4" />
    </marker>
    <marker
       style="overflow:visible"
       id="Arrow2Send-3"
       refX="0"
       refY="0"
       orient="auto"
       inkscape:stockid="Arrow2Send"
       inkscape:isstock="true">
      <path
         transform="matrix(-0.3,0,0,-0.3,0.69,0)"
         d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
         style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round"
         id="path68697-0" />
    </marker>
  </defs>
  <g
     inkscape:label="Ebene 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(-41.537344,-60.215376)">
    <g
       id="g69839"
       transform="matrix(0.37262531,0,0,0.37262531,-6.1711126,31.925465)"
       style="fill-rule:evenodd;stroke:#108000;stroke-opacity:1">
      <g
         id="g69827"
         style="fill-rule:evenodd;stroke:#108000;stroke-opacity:1">
        <rect
           style="opacity:0.971564;mix-blend-mode:normal;fill:#098000;fill-opacity:0.501393;fill-rule:evenodd;stroke:#108000;stroke-width:1;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
           id="rect86-9"
           width="97.898438"
           height="67.95063"
           x="270.56329"
           y="74.766342"
           ry="17.762169"
           transform="matrix(0.4220691,0,0,0.4220691,147.68606,52.931391)" />
      </g>
      <text
         xml:space="preserve"
         style="font-style:normal;font-weight:normal;font-size:2.68014px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.111672;stroke-opacity:1"
         x="276.55472"
         y="90.539818"
         id="text16494-8"><tspan
           id="tspan16492-9"
           style="font-size:2.68014px;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.111672;stroke-opacity:1"
           x="276.55472"
           y="90.539818"
           sodipodi:role="line">Ardunino</tspan></text>
    </g>
    <g
       id="g106990"
       style="stroke:#66de03;stroke-opacity:1"
       transform="matrix(0.61676117,0,0,0.61676117,-72.465685,11.82445)">
      <g
         id="g69827-0"
         style="fill:#a2ff00;fill-opacity:0.504178;fill-rule:evenodd;stroke:#66de03;stroke-opacity:1"
         transform="matrix(0.60416467,0,0,0.60416467,26.748816,32.591246)">
        <rect
           style="opacity:0.971564;mix-blend-mode:normal;fill:#a2ff00;fill-opacity:0.504178;fill-rule:evenodd;stroke:#66de03;stroke-width:1;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
           id="rect86-9-2"
           width="97.898438"
           height="67.95063"
           x="270.56329"
           y="74.766342"
           ry="17.762169"
           transform="matrix(0.4220691,0,0,0.4220691,147.68606,52.931391)" />
      </g>
      <text
         xml:space="preserve"
         style="font-style:normal;font-weight:normal;font-size:1.61925px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.0674683;stroke-opacity:1"
         x="192.59203"
         y="87.000122"
         id="text16494-8-7"><tspan
           id="tspan16492-9-6"
           style="font-size:1.61925px;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.0674683;stroke-opacity:1"
           x="192.59203"
           y="87.000122"
           sodipodi:role="line">Messrechner</tspan></text>
    </g>
    <g
       id="g53215"
       transform="matrix(0.59973583,0,0,0.59973583,-54.898976,23.478845)">
      <g
         id="g104514">
        <rect
           style="opacity:0.971564;mix-blend-mode:normal;fill:url(#linearGradient104483);fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient38242);stroke-width:0.434051;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
           id="rect86"
           width="42.492897"
           height="29.494028"
           x="327.07794"
           y="61.471546"
           ry="7.7096844" />
        <text
           xml:space="preserve"
           style="font-style:normal;font-weight:normal;font-size:2.75622px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:#020f00;stroke-width:0.114842;stroke-opacity:1"
           x="338.23734"
           y="67.376602"
           id="text16494"><tspan
             id="tspan16492"
             style="font-size:2.75622px;fill:#000000;fill-opacity:1;stroke:#020f00;stroke-width:0.114842;stroke-opacity:1"
             x="338.23734"
             y="67.376602"
             sodipodi:role="line">Klimakammer</tspan></text>
      </g>
    </g>
    <path
       style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.308381;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-start:url(#Arrow1Sstart-8);marker-end:url(#Arrow2Send)"
       d="m 107.43897,69.239103 33.24637,-0.08734"
       id="path69424"
       inkscape:connector-type="polyline"
       inkscape:connector-curvature="0" />
    <path
       style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.308381;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-start:url(#Arrow1Sstart-8-0);marker-end:url(#Arrow2Send-3)"
       d="m 57.642018,69.239103 33.246379,-0.08734"
       id="path69424-2"
       inkscape:connector-type="polyline"
       inkscape:connector-curvature="0" />
  </g>
</svg>

这样转换过程就不会再崩溃了。

为了使 LaTeX 输出更好一些,我建议将字体调小并且使用无衬线字体:

\documentclass{article}
\usepackage{svg}
\begin{document}
\begin{figure}[htpb]
    \centering
    \includesvg[pretex=\tiny\sffamily]{Zeichnung.svg}
    \caption{Broken svg}
    \label{fig:Broken}
\end{figure}
\end{document}

结果:

在此处输入图片描述

为了进一步改进它,您可以在 Inkscape 中编辑 SVG 以使标签居中,甚至可以直接从 Inkscape 导出为 PDF 并包含 PDF 而\includegraphics不是与包一起转换svg,这样您就可以更好地控制结果。

注意:我认为第二个节点应该被标记为Arduino并不是阿杜尼诺

相关内容