Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've been learning LaTeX and this community has been very helpful. Currently, I'm trying to set up corporate letters but as a newbie I'm encountering a variety of challenges, so I'm posting them one by one instead of putting it in the comments... maybe this helps others as well.

Anyway, I am trying to implement this answer that indicates that I can use vbox to float an image to the right of my header. I almost have this working, but I now try to adjust this to get my logo to stick to the top of the page. So I want to have this at the right top of my document. This is quite difficult! When I place the vbox, it creates unwanted spacing, for some odd reason. So I can not get the logo to be at the right top, even though I 'reset' every possible margin to 0 (in my opinion). Here is my distilled code:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\graphicspath{{./img/}}
\usepackage{color}
\usepackage{xcolor}
\definecolor{orange}{HTML}{DD4616}
\definecolor{white}{HTML}{FFFFFF}
\usepackage{fullpage}
\usepackage[margin=0cm, paperwidth=215.9mm, paperheight=30mm,top=0cm]{geometry}
\parindent=0pt

\begin{document}
\fboxsep0pt

\pagecolor{orange}


\fbox{\vbox to 0pt{\hfill\fbox{\includegraphics[height=3cm]{logo}}}}

\end{document}

I've used a full black logo for illustrative purposes. Here you can see this:

enter image description here

The black line is the vbox border. For some reason, it jumps down. The only way to get rid of this that I found out about is this:

Make an invisible vbox

Which means that I need to add:

\edef\theprevdepth{\the\prevdepth}\nointerlineskip
\vbox to 0pt{...}\prevdepth=\theprevdepth

But there are two problems with this:

  • I get an error with I try this (Improper \prevdepth.)
  • More importantly, I really want to understand my code at this point, and get to master the basics of positioning elements. This feels overcomplicated and I do not understand it at all.

Is there any easy way to position an image at the right top of a document?

share|improve this question
    
The latest TUGboat has an article about designing letters with the hletter package. If you haven't had a chance to look at it then it may be worth your while because it may save you some work. –  Marc van Dongen Feb 11 '12 at 6:55

4 Answers 4

up vote 7 down vote accepted

The \vbox is anchored to the baseline. Also, since there is an additional \topskip at the top of the page between the header and the first line of text. So, jumping vertically -\baselineskip-\topskip pushes the \vbox of height 0pt tight against the upper part of the page boundary.

Here's your MWE:

enter image description here

\documentclass[a4paper]{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\definecolor{orange}{HTML}{DD4616}
\definecolor{white}{HTML}{FFFFFF}
\usepackage{fullpage}% http://ctan.org/pkg/fullpage
\usepackage[margin=0cm, paperwidth=215.9mm, paperheight=30mm]{geometry}
\setlength{\parindent}{0pt}
\setlength{\fboxsep}{-\fboxrule}%
\begin{document}
\pagecolor{orange}%
\vspace*{\dimexpr-\baselineskip-\topskip\relax}

\fbox{\vbox to 0pt{\hfill\fbox{\includegraphics[height=3cm]{html5}}}}
\end{document}

Some comments about the code:

  • You have to use \vspace* for vertical space at the top of the page;
  • \dimexpr...\relax is used as a dimension expression for combining lengths (or dimensions). You can also include the calc package which allows you to forego this notation and use -\baselineskip-\topskip as is;
  • I use \setlength rather than \<len>=<dim> - that's just the LaTeX way; the latter is the TeX way;
  • margin=0cm is equivalent to left=0cm,right=0cm,bottom=0cm,top=0cm in geometry, so I dropped top=0cm;
  • I set \fboxsep to -\fboxrule. This way the rule is actually drawn within the bounding box. Otherwise it would add .4pt to each of the sides (a total of .8pt vertically and horizontally) even if you use \setlength{\fboxsep}{0pt};
  • Loading xcolor is sufficient, so you don't need to load color.
share|improve this answer

With TikZ and the current page node, you can place the image right at the top right corner of the page, just set the image node anchor to north east. All you need to add to your code is

\usepackage{tikz}

in the preamble, and then in your code

\begin{tikzpicture}[remember picture, overlay]
  \node [anchor=north east, inner sep=0pt]  at (current page.north east)
     {\includegraphics[height=3cm]{logo}};
\end{tikzpicture}

logo at top right

share|improve this answer

It is normally sufficient to say:

\usepackage[margin=0cm, 
            paperwidth=215.9mm, 
            paperheight=30mm,
            top=-10pt]{geometry}

Geometry dimensions can be negative as well. In the above top is set to top=-10pt.

share|improve this answer
1  
...since \topskip is 10pt. –  Werner Feb 11 '12 at 5:18

Without using a special geometry setting:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\pagecolor{orange}
\vspace*{\dimexpr-1in-\topmargin-\headsep-\headheight-\baselineskip}%
\hspace*{\dimexpr-1in-\evensidemargin-\parindent}%
\makebox[\paperwidth][r]{\frame{\includegraphics[height=3cm]{tiger}}}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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