0

I'm creating a simple template to be used by my students in their assignments. It consists of "article" document class but with an aditional content on top of first page. The content is declared in the \newcommand below:

\documentclass{article}
\usepackage{graphicx}
\usepackage{wrapfig}

\newcommand\makeheader{
\begin{wrapfigure}{l}{4\baselineskip}
\includegraphics[height=4\baselineskip]{figures/logo.jpg}
\end{wrapfigure}
University name \\
Institute name \\
Graduation course \\
Course name}

\title{My assignment}
\author{An student }
\date{April 2020}

\begin{document}

\makeheader

\maketitle

Here goes my doc...


\end{document}

Three undesired things happens:

  1. The custom \makeheader forces \maketitle move to a second page, that is undesired.

  2. The first sentence (University name) in my custom "header" wrongly skips horizontaly to right. That is also undesired.

  3. The title in \maketitle also skips horizontaly to right. Very undesired.

How can I fix these 3 undesired behaviors?

Best regards.

2 Answers 2

1

One approach could be use a fancy header:

mwe

\documentclass{article}
\usepackage{graphicx,lipsum}
\usepackage{geometry}
\usepackage{fancyhdr}
\fancypagestyle{Univlogo}{%
\renewcommand{\headrulewidth}{0pt}% no header line
\fancyhead[L]{\hspace{-1cm}\includegraphics[height=4\baselineskip]{example-image}
\quad\begin{minipage}[b][4\baselineskip][c]{.5\textwidth}\sffamily
University name \\
Institute name \\
Graduation course \\
Course name
\end{minipage}}}

\newgeometry{margin=1in}

\title{My assignment}
\author{An student }
\date{April 2020}

\begin{document}

\maketitle
\thispagestyle{Univlogo}


Here goes my doc... \lipsum[1]

\end{document}

Another could be the texpos package:

\documentclass{article}
\usepackage{graphicx,lipsum}
\usepackage[absolute]{textpos}
\def\UniLogo{\begin{textblock}{9}(.5,.5)
\includegraphics[height=4\baselineskip]{example-image}
\quad\begin{minipage}[b][4\baselineskip][c]{.5\textwidth}\sffamily
University name \\
Institute name \\
Graduation course \\
Course name
\end{minipage}
\end{textblock}}


\title{My assignment}
\author{An student }
\date{April 2020}

\begin{document}

\maketitle\UniLogo

Here goes my doc... \lipsum[1]

\end{document}
5
  • and which method do you think is more maintainable? I also pretend to use fancyhdr to display title and author name at top of all pages besides the first one (in case of printing, since pages can get messed up during assignment correction), how to make those not conflict with your first approach? ( I know that was not on original post).
    – Lin
    Commented Apr 21, 2020 at 8:45
  • @Lin textpos approach is not dependent of the rest of the document layout whereas this is not true for a header (if you change the margins, the logo will move) but beside this, both are based in well-know packages, actively maintained in CTAN, so ...
    – Fran
    Commented Apr 21, 2020 at 9:07
  • @Lin if you want the logo in all the pages then the easier could be use two header styles: one for the first page (logo only at the left) and another more complex (logo + whatever) for the rest of the document.
    – Fran
    Commented Apr 21, 2020 at 9:32
  • No. No logo in all pages. The opposite. I would like the logo just in first page. The header of all other pages would be only AUTHOR PAGENUM TITLE
    – Lin
    Commented Apr 21, 2020 at 9:38
  • @Lin Oh, sorry. Then there are no problems since \thispagestyle only apply to the actual page (the first if it is placed just after \maketitle). The rest of the document will use the default style or any other if you make \fancypagestyle{whatever}{...} and then \pagestyle{whatever}.
    – Fran
    Commented Apr 21, 2020 at 9:58
0

Here is a solution using a tikzpicture and its very convenient current page node. You need the remember picture option to access this node and the overlay option so that the TeX box produced by the tikzpicture at the place in the document where \makeheader appears takes no space. Put this command in a paragraph that occurs early enough to be on the first page (see the example below); this way, you don't disturb placement of the title. You need to compile twice because of the remember picture mechanism.

Note: if you use shift={(0cm,0m)} instead of shift={(1.2cm,-1.2cm)}, the top left corner of the image will be placed exactly at the top left corner of the page (also known as “north west”).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{graphicx}
\usepackage{lipsum}        % only for the dummy text used here

\newcommand*{\makeheader}{%
  \begin{tikzpicture}[remember picture, overlay]
    \node[inner sep=0, below right, shift={(1.2cm,-1.2cm)}] (logo)
      at (current page.north west)
      {\includegraphics[height=4\baselineskip]{example-image}};
    \node[right=2em of logo, align=left]
      {%
        University name   \\
        Institute name    \\
        Graduation course \\
        Course name
      };
  \end{tikzpicture}%
}

\title{My assignment}
\author{A student}
\date{April 2020}

\begin{document}

\maketitle

\makeheader
Here goes my doc. \lipsum[1]

\end{document}

enter image description here

You must log in to answer this question.

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