1

I am encountering a weird error when setting a background to the pages of my LaTeX document.

The MWE is the following:

\documentclass[11pt, a4paper]{article}

\usepackage{pgffor} % Per i loop
\usepackage{background}
\usepackage{graphicx}
\usepackage{lipsum}

\newcommand{\sfondo}[1]{\backgroundsetup{angle=0, opacity=0.5, scale=1, contents=\includegraphics{./sfondi dossier/sfondo#1.png}}}

\begin{document}
\foreach \pagenum in {1,...,10}{

    \sfondo{\pagenum}

    \lipsum[1]

    \newpage

}
\end{document}

My IDE is TeXstudio. If I execute the code directly from there, I get no error. If I execute it from a terminal, though, I see that I'm receiving a series of alerts:

LaTeX Warning: File `./sfondi dossier/sfondo1.png' not found on input line 19.

<./sfondi dossier/sfondo1.png, id=4, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo1.png> [1{/var/lib/texmf/fonts/map/pdftex/updmap/pd
ftex.map} <./sfondi dossier/sfondo1.png>]

LaTeX Warning: File `./sfondi dossier/sfondo2.png' not found on input line 19.

<./sfondi dossier/sfondo2.png, id=13, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo2.png> [2 <./sfondi dossier/sfondo2.png>]

LaTeX Warning: File `./sfondi dossier/sfondo3.png' not found on input line 19.

<./sfondi dossier/sfondo3.png, id=18, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo3.png> [3 <./sfondi dossier/sfondo3.png>]

LaTeX Warning: File `./sfondi dossier/sfondo4.png' not found on input line 19.

<./sfondi dossier/sfondo4.png, id=23, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo4.png> [4 <./sfondi dossier/sfondo4.png>]

LaTeX Warning: File `./sfondi dossier/sfondo5.png' not found on input line 19.

<./sfondi dossier/sfondo5.png, id=28, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo5.png> [5 <./sfondi dossier/sfondo5.png>]

LaTeX Warning: File `./sfondi dossier/sfondo6.png' not found on input line 19.

<./sfondi dossier/sfondo6.png, id=33, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo6.png> [6 <./sfondi dossier/sfondo6.png>]

LaTeX Warning: File `./sfondi dossier/sfondo7.png' not found on input line 19.

<./sfondi dossier/sfondo7.png, id=38, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo7.png> [7 <./sfondi dossier/sfondo7.png>]

LaTeX Warning: File `./sfondi dossier/sfondo8.png' not found on input line 19.

<./sfondi dossier/sfondo8.png, id=44, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo8.png> [8 <./sfondi dossier/sfondo8.png>]

LaTeX Warning: File `./sfondi dossier/sfondo9.png' not found on input line 19.

<./sfondi dossier/sfondo9.png, id=49, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo9.png> [9 <./sfondi dossier/sfondo9.png>]

LaTeX Warning: File `./sfondi dossier/sfondo10.png' not found on input line 19.


<./sfondi dossier/sfondo10.png, id=54, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo10.png> [10 <./sfondi dossier/sfondo10.png>]

Notice that it doesn't ask me for any input (I read that when pdflatex can't find a file it asks the user to give a new path). Plus, and here's the big thing, actually the PDF comes out fine. In the following screenshot in fact you can see how every page has its own background.

screenshot

There are two issues though. As first thing, the image doesn't go exactly where it should. As you can see it gets slightly moved horizontally, to the right (the images have the same size of an A4 paper page), so I have to move it through the hshift and vshift attributes in the \backgroundsetup. The shifting is quite precise, but it's not always exactly the same. In the actual document I'm working on, the 100th, last, background, is slightly more tilted to the right than the others.

Also, the compiling is very slow. This surely comes from the size of the pictures and of the final pdf document, but I have the suspect that this error is slowing the compiling even more. Considering that the final tex document will be responsible for a big server-side procedural exportation I'd like to diminish the compilation times of the document and taking out this error seems like being the first step for it.

marked as duplicate by gernot, Torbjørn T., Zarko, Mico, Stefan Pinnow Mar 6 '17 at 18:31

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.

  • 1
    Can you try with a path without spaces in the folder names? – user36296 Mar 6 '17 at 15:32
  • 2
    I can't reproduce the warnings but the first thing I would try is to remove the space in the folder name. – Ulrike Fischer Mar 6 '17 at 15:32
  • damn, the issue is completely solved already O_O Is there a particular reason why the space was giving me this issue? – il mietitore Mar 6 '17 at 15:36
  • 3
    Spaces oin file and directory names are often problematic and need special attention, so often better to avoid them. For example is in your Linux you'll have to escape the spaces to for example move the file on the command line (or incase in in "...") – daleif Mar 6 '17 at 15:40
  • Sounds legit. If one of you posts that as answer I'll tick it as solution – il mietitore Mar 6 '17 at 15:42

Browse other questions tagged or ask your own question.