插入一个SVG到LaTeX文档中。

huangapple go评论75阅读模式
英文:

Inserting a SVG into a LaTeX document

问题

以下是您要翻译的内容:

我想在我的Latex文档中添加一个徽标。由于使用\includesvg对我不起作用(我正在使用ubuntu,已安装inkscape),所以我不得不手动将svg文件转换为pdf文件。

但当我想在我的标题中包含此文件(请参见01_titel.tex),它打印出一堆字符错误。 有谁知道如何修复这个问题并将徽标包含为矢量图形?

您可以在这里找到tex文件以及我要包含的pdf/svg文件:这里

编译文件时出错

最简单的方法是以某种方式直接将svg包含到tex文件中。

以下是您提供的TeX文件的一部分:

%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}

英文:

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}

答案1

得分: 2

这是一段关于LaTeX中使用SVG图像的代码,它使用了CTAN上的svg包。这个包允许你像使用graphicx包中的\includegraphics一样加载SVG文件,还可以接受诸如widthscale等可选参数。如果需要其他翻译,请告诉我。

英文:

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

插入一个SVG到LaTeX文档中。

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}

huangapple
  • 本文由 发表于 2023年3月31日 04:42:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定