1

I'm stuck in a process that is seemingly trivial but I cant find an easy solution to it.

I want to replicate the following docx header

header

Imagine the black and white rectangles are a pdf and png figures. The "table of contents" is the actual body of text. As you guys can see, the header should extend beyond the text in both directions. I have the precise measurements of the distance between the figures and the page limits.

The problem is I can't find a way to specify this distance correctly.

I tried fancyhdr but could not find a way to extend the header in both directions (it either would extend the right or to the left.

I then moved to titlesec package, and now I can extend both ways but I hit two bumps. I can use the \widenhead{}{} to specify how much the header should invade the margin. Yet I cannot find a way to recover the information on what is the actual margin of the document, so I can make that the header cover the entire page width. Second, \includegraphics seems to always want to place the figure name which send the figures to a second line of the header.

Here's the minimum reproducible example. I even gave on one of the picture so I can try to solve one problem at a time:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage[pagestyles]{titlesec}
\usepackage[top=24pt,bottom=24pt]{geometry} %For a cover page
\usepackage{lipsum}


\begin{document}


\lipsum[50] % simulation of cover page

\newpage
\newgeometry{top=2cm}

\newpagestyle{normal}{
  \headrule
  \sethead{}{}{\includegraphics[width=7.52cm,height=1.46cm]{example-image-b}} %breaks
  \widenhead{3cm}{3cm}   % I wish I could set this to cover the entire length      
}

\pagestyle{normal}



\lipsum[50]


\end{document}

output

What am I doing wrong?

4
  • your example is not complete and doesn't compile, so can't be used to reproduce your problem. Commented Jun 6 at 15:23
  • Please show us a short compilable TeX code resulting in your issue! Then we do not have to guess what you are doing ...
    – Mensch
    Commented Jun 6 at 15:25
  • i've edit the example for something that compiles on overleaf. Please look at page 2
    – JMenezes
    Commented Jun 6 at 15:28
  • for the picture use an additional pair of braces to protect it from the \sethead command. (Or store it in a box and use that). Commented Jun 6 at 15:44

1 Answer 1

0

Ok, I figure it out. \sethead is very particular on the number of arguments (as it specifies in the manual).If more than curly bracket is present you MUST also present all square brackets.

Placing \sethead{\includegraphics[width=7.52cm,height=1.46cm]{example-image-a}}{}{\includegraphics[width=7.52cm,height=1.46cm]{{example-image-b}}} will lead to an error even if filenames are protected by extra curly brackets.

However, running \sethead[][][]{\includegraphics[width=7.52cm,height=1.46cm]{example-image-a}}{}{\includegraphics[width=7.52cm,height=1.46cm]{{example-image-b}}} does work as expected.

Functioning code below:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage[pagestyles]{titlesec}
\usepackage[top=24pt,bottom=24pt]{geometry} %For a cover page
\usepackage{lipsum}


\begin{document}


\lipsum[50] % simulation of cover page

\newpage
\newgeometry{top=2cm}

\newpagestyle{normal}{
  \headrule
  \sethead{\includegraphics[width=7.52cm,height=1.46cm]{example-image-a}}{}{\includegraphics[width=7.52cm,height=1.46cm]{example-image-b}} %breaks
  \widenhead{3cm}{3cm}   % I wish I could set this to cover the entire length      
}

\pagestyle{normal}



\lipsum[50]


\end{document}

Which compiles to:

enter image description here

I still haven't figure out how can I replace the "3cm" by the actual realized paper margin width, but I'm basically given up on that. I sense I'll not be able to produce the standard of an adequate example in due time.

1
  • I didn't say that you should protect the filename, but the whole \includegraphics command. For the width try something like \widenhead{\Gm@lmargin}{\Gm@rmargin} (with a \makeatletter before the \newpagestyle) Commented Jun 6 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .