Search code examples
pdfsvglatextextexstudio

Inserting a SVG into a LaTeX document


I would like to add a logo into my Latex document. Since using \includesvg did not work for me (I am using ubuntu and I have installed incscape) I resorted to manually converting the svg file into a pdf file.

But when I wanted to include this file in my Title (see 01_titel.tex) it print a bunch of character-errors. Does anybody know how to fix this and include the logo as a vector-graphic ?

You can find the tex file and the pdf / svg I want to include here: Here

Error when compiling the file

The easiest way would be to somehow include the svg directly into the tex file.

Here is my Tex File:

%Dokumentklasse
\documentclass[a4paper,12pt]{scrreprt}
\usepackage[left= 2.5cm,right = 2cm, bottom = 4 cm]{geometry}
%\usepackage[onehalfspacing]{setspace}
% ============= Packages =============

% Dokumentinformationen
\usepackage[
    pdftitle={Titel der Abschlussarbeit},
    pdfsubject={},
    pdfauthor={Euer Name},
    pdfkeywords={}, 
    %Links nicht einrahmen
    hidelinks
]{hyperref}


% Standard Packages
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx, subfig}
\graphicspath{{img/}}
\usepackage{fancyhdr}
\usepackage{lmodern}
\usepackage{color}

% zusätzliche Schriftzeichen der American Mathematical Society
\usepackage{amsfonts}
\usepackage{amsmath}


%nicht einrücken nach Absatz
%\setlength{\parindent}{0pt}


% ============= Kopf- und Fußzeile =============
\pagestyle{fancy}
%
\lhead{}
\chead{}
\rhead{\slshape \leftmark}
%%
\lfoot{}
\cfoot{\thepage}
\rfoot{}
%%
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

% ============= Package Einstellungen & Sonstiges ============= 
%Besondere Trennungen
\hyphenation{De-zi-mal-tren-nung}


% ============= Dokumentbeginn =============

\begin{document}
%Seiten ohne Kopf- und Fußzeile sowie Seitenzahl
\pagestyle{empty}
\begin{figure}
\centering
\def\svgwidth{175pt}
\input{img/thws-logo.pdf}
\caption{logo}
\end{figure}

\end{document}

Solution

  • There's a package svg on CTAN, which adds \includesvg{<filename no ext>}, which simply loads your file similarly to \includegraphics from graphicx and accepts optional arguments like width, scale etc.

    The code below should render following image

    enter image description here

    EDIT. Note the block filecontents*. This is to create a file in a root folder and is added to make example self-content. The test-svg.svg file would just be an external file copied to a project folder by you.

    The code

    \begin{filecontents*}[overwrite]{test-svg.svg}
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!-- Created with Inkscape (http://www.inkscape.org/) -->
    
    <svg
       width="60.103493mm"
       height="50.85656mm"
       viewBox="0 0 60.103493 50.85656"
       version="1.1"
       id="svg5"
       xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
       xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:svg="http://www.w3.org/2000/svg">
      <sodipodi:namedview
         id="namedview7"
         pagecolor="#505050"
         bordercolor="#ffffff"
         borderopacity="1"
         inkscape:showpageshadow="0"
         inkscape:pageopacity="0"
         inkscape:pagecheckerboard="1"
         inkscape:deskcolor="#505050"
         inkscape:document-units="mm"
         showgrid="false" />
      <defs
         id="defs2" />
      <g
         inkscape:label="Layer 1"
         inkscape:groupmode="layer"
         id="layer1"
         transform="translate(-66.909471,-25.283422)">
        <rect
           style="fill:#ff0000;stroke:#000000;stroke-width:1.76389"
           id="rect111"
           width="35.796261"
           height="26.072519"
           x="67.79142"
           y="26.165365" />
        <ellipse
           style="fill:#00ffff;stroke:#000000;stroke-width:1.76389"
           id="path165"
           cx="107.6892"
           cy="57.111996"
           rx="18.44182"
           ry="18.146046" />
      </g>
    </svg>
    \end{filecontents*}
    %%%
    \documentclass{article}
    \usepackage{svg}
    
    \begin{document}
    \begin{figure}[tbh]
        \centering
        \includesvg[scale=1.2]{test-svg}
        \caption{Included SVG file}\label{fig:testsvg}
    \end{figure}
    \end{document}