2

first question in this stack community. I'm trying to create a new style for title page:

\documentclass{article}

\usepackage[italian]{babel}
\usepackage[paper=a4paper, top=4cm, bottom=2.5cm, left=2.0cm, right=2cm]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage{afterpage}
\usepackage{fancyhdr}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage{wrapfig}
\usepackage{lastpage}

\usepackage{lipsum}
\usepackage{tikz}

\usepackage{adjustbox}

\definecolor{green}{RGB}{0,89,0}
\hypersetup{
    colorlinks=true,
    urlcolor= green,
    linkcolor = black,
}

\pagestyle{fancy}

\fancyhead{}
\fancyfoot{}
\fancyfoot[C]{\url{mycompany.com}}

\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}

\begin{document}
\begin{titlepage}

\thispagestyle{fancy}

\begin{adjustbox}{width=\paperwidth} 
  \begin{tikzpicture}
  \makebox[\textwidth][c]{\includegraphics[width = \textwidth]{Logo.jpg}}
  \end{tikzpicture}
  \end{adjustbox}

  \begin{center}
    \vspace*{3cm}

    \rule{\textwidth}{1.6pt}\vspace*{-\baselineskip}\vspace*{3.5pt}
    \rule{\textwidth}{0.4pt}

    \vspace{2\baselineskip}

    {\Huge Sample Report\\}
    \vspace{2\baselineskip}

    \rule{\textwidth}{0.4pt}\vspace*{-\baselineskip}\vspace{3.5pt}
    \rule{\textwidth}{1.6pt}

    \vspace{2\baselineskip}

    \vspace{2\baselineskip}
    {\LARGE  Italy \\}
    \vspace{1\baselineskip}

    {\large  23 May 2019 \\}

  \end{center}
  \end{titlepage}
\fancyhead[R]{Sample Report}
\fancyfoot[R]{Page \thepage~of \pageref{LastPage}} % start page counting

\lipsum[1-8]
\lipsum[1-8]


\end{document}

The pdf file renders fine but I get an error in my IDE (pasted below) corresponding to the \end{adjustbox} - not sure how I can fix this?

! Package graphics Error: Division by 0.See the graphics package documentation for explanation.Type H for immediate help.... \end{adjustbox}

Here's what I want the page to look like (blanked out areas - title, name, header etc. had confidential identifying information so had to be removed):

enter image description here

  • Welcome to tex.sx. – barbara beeton Jul 15 at 18:55
  • @Gautam \makebox[\textwidth][c]{...} is useless given the \includegraphics[width = \textwidth]{...} and the contents of the tikzpicture environment is not valid TikZ syntax. If you replace the whole \begin{tikzpicture} ... \end{tikzpicture} with \includegraphics[width=\textwidth]{example-image}, the compilation works (but then, the \begin{adjustbox}{width=\paperwidth} ... \end{adjustbox} seems to be a convoluted way to do something that could probably be done with simply \includegraphics). Also, please use example-image instead of Logo.jpg: it's always available. – frougon Jul 15 at 19:15
  • @Gautam Maybe what you want is \makebox[0pt]{\includegraphics[width=\paperwidth]{example-image}}\par at the beginning of the center environment. – frougon Jul 15 at 19:22
  • @frougon thanks! It works - I don't get any errors anymore. However, the image that I was using on my title page doesn't span the entire page anymore (it did previously). I tried using \begin{tikzpicture} with \paperwidth but that didn't work either - I have a small amount of empty space left on the left margin now. – Gautam Jul 15 at 19:23
  • @frougon using \makebox in the \begin{center} loop places the image in the body of the document whereas I want it in the header only. – Gautam Jul 15 at 19:25
1

The code:

\makebox[\textwidth][c]{\includegraphics[width = \textwidth]{Logo.jpg}}

that you put inside the tikzpicture doesn't conform to any TikZ syntax (it would be valid inside a node command, but the \makebox[\textwidth][c]{...} is useless anyway, since you are already passing width=\textwidth to \includegraphics). Thus, TikZ doesn't recognize it and, being a very forgiving parser, simply ignores it. As a consequence, the resulting tikzpicture has zero width. Then you put this tikzpicture inside \begin{adjustbox}{width=\paperwidth} ... \end{adjustbox}. This is what triggers the division by 0, when adjustbox divides \paperwidth by the width of the tikzpicture (0pt) in order to compute the scale factor.

The following code will produce the desired layout:

\begin{tikzpicture}[remember picture, overlay]
  \node[inner sep=0, anchor=north] at (current page.north)
    {\includegraphics[width=\paperwidth]{example-image}};
\end{tikzpicture}

for instance after your \thispagestyle{fancy} (but you may want to put \thispagestyle{empty} for the first page instead, if this is the only thing you wanted in the header there). The scaling preserves the aspect ratio of the image. Here is a full, self-contained example:

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[remember picture, overlay]
  \node[inner sep=0, anchor=north] at (current page.north)
    {\includegraphics[width=\paperwidth]{example-image}};
\end{tikzpicture}

\end{document}

Because of the remember picture option, you need to compile the document twice.

enter image description here

Other errors in your code

Concerning the other error message that is printed with your code, namely:

pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has been already used, duplicate ignored

it is explained here. In short, you can solve it by putting for instance \pagenumbering{Alph} before \begin{titlepage} and \pagenumbering{arabic} after \end{titlepage}.

Also, this kind of thing is incorrect:

{\Huge Sample Report\\}
\vspace{2\baselineskip}

You can use either:

{\Huge Sample Report\par}
\vspace{2\baselineskip}

or

{\Huge Sample Report\\[2\baselineskip]
other text in Huge size}

(the latter only if there is text immediately following, as in this example).

  • Thanks! This works too - I seem to lose the horizontal \headrule but I'm guessing that's been covered by the image file - I am okay with that. I do want some text in the page (need to stick with the official template) namely the document title, author name and date. Is there a way to add a 'footer' as well? perhaps by using another tikzpicture but anchored south at current page.south? – Gautam Jul 15 at 19:55
  • Yes, or \fancyfoot, depending on the positioning requirements. With the current page TikZ node, you can easily place stuff flush against the page edges. Headers and footers (fancyhdr) are not that close to the edges, unless you define layout parameters very specially. They are more suited for run-in headings and page numbers. I've explained how to fix another error in your code, please look at the updated answer. – frougon Jul 15 at 20:00
  • @Gautam I explained why you got the division by zero, proposed a solution that apparently achieves the layout you wanted and fixed several other unrelated errors in your code. Is there any reason why you didn't upvote nor accept my answer? Please consult “How do you accept an answer?” in case you don't know what this means, thanks. – frougon Jul 16 at 8:12
  • Thanks! I was trying it out until now - it works. – Gautam Jul 16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.