0

This question already has an answer here:

this is my first post in this forum, but i have been here a thousand times, enjoying the high-quality answers to often also good quality questions. So i try my best to also provide all needed information, and a MWE. I am using Pdflatex in the TeXnicCenter on a Windows 7 machine.

In my thesis i am using a lot of SVG graphics, which i include in a nice workflow. I've set this up along some lines that are common concerning the question "how to include SVG?". It uses a \newcommand{\includesvg} and exports, if necessary, the SVG via Inkscape to pdf_tex, which is then inputted via \input{...pdf_tex}.

Now i've always felt that these images don't center correctly, and now i've broken it down to this MWE. In the result it is obvious, that the centering goes slightly wrong, when the pdf_tex is included when used through the \includesvg command. Which, from my little understanding of Tex, doesn't make much sense. So the question arieses: Does \newcommand add any margin/border/alignment to it's content?

Unfortunately, to run the MWE, you'd need a SVG file called "blackbox.svg". In the example it is just a wide solid rectangle, that's all.

In the MWE, on the first output-page i include the SVG graphic "blackbox" using the minimalistic \includesvg command. For the captions, i use the caption package. This is for illustrating how the graphic is in this case not centered. The rectangle in the output has moved slightly to the left, like 6pt or so. On the second page, everything is fine. But there is nothing much differently done, except that the two lines

\def\svgwidth{\figurewidth}
\input{#1.pdf_tex}

are not "called" through the command definition. Does it make a difference? And how would i solve the difference? Because i really need that command.

Here is the MWE:

\documentclass{article}

\usepackage{blindtext}
\usepackage{caption}
\usepackage[pdftex]{graphicx}
\usepackage{calc}

\newlength{\figuremargin}
\setlength{\figuremargin}{40pt}
\newlength{\figurewidth}
\setlength{\figurewidth}{\columnwidth-\figuremargin}

%%% SETUP OF CAPTIONS
    \DeclareCaptionFormat{myformat}{#1#2#3\hrulefill}
    \captionsetup{
        margin={\figuremargin/2,\figuremargin/2},
        font={footnotesize,sf},
        justification=justified,
        format=myformat
    }
%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\includesvg}[1]{
    \def\svgwidth{\figurewidth}
    \input{#1.pdf_tex}
}

\begin{document}
    \blindtext[1]
    \begin{figure}[!htb]
        \caption{\blindtext[1]}
        \centering
        \includesvg{blackbox}
    \end{figure}
    \blindtext[1]
    \newpage
    \blindtext[1]
    \begin{figure}[!htb]
        \caption{\blindtext[1]}
        \centering
        \def\svgwidth{\figurewidth}
        \input{blackbox.pdf_tex}
    \end{figure}
    \blindtext[1]
\end{document}

In this image you can see the shift to the left of the graphic.

This image shows the slight shift of the graphic to the left I hope there is something i can do with that \newcommand. Do you guys have any hints for me?

Thanks! Janos

marked as duplicate by egreg macros Jul 25 '14 at 22:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.