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 am trying to right-align some text with a logo, i.e. I would like to place some text to the left of a logo, and centre this text vertically with respect to the logo.

I’ve attached a pdf to be more clear about what I’m trying to do.

I would like to place the text “Faculty of Science” to the left of the black “logo” in the pdf above. In this example, the blue rectangular border is 1cm from the edge of the page, and the 2.5cm wide square logo is 1.25mm from the blue rectangular border.

I think textpos is the solution to what I’m trying to do, and I came up with the code below.

\documentclass{article}

% ...

\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{1mm}
\setlength{\TPVertModule}{\TPHorizModule}
\textblockorigin{0mm}{0mm} % start everything at the top-left corner

\begin{document}

% ...

\begin{textblock}{100}[0,0](120, 23.75)

\large \textit{\textbf{Faculty of Science}}

\end{textblock}

% ...

\end{document}

However, I would like something that works whatever the text I wish to place (i.e the right most letter of the last word should always be at the same fixed distance from the logo, say 1cm, and should also be vertically centered with respect to the logo). Here, every time I change the text or its style, I have to fiddle around with the coordinates until I get something that looks right.

Any ideas?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

You can use minipages for this

screenshot

Note that the minipage environment takes a mandatory <width> argument, and an optional position argument. I've used [c] to mean centred in the below.

I've used an empty box\mbox{} so that the \hfill has something to push up against.

Adjust the widths as necessary, and don't forget to remove the demo option from the graphicx package.

\documentclass{article}
\usepackage[showframe=true]{geometry}
\usepackage[demo]{graphicx}

\begin{document}

\mbox{}\hfill
\begin{minipage}[c]{4cm}
Faculty of science
\end{minipage}%
\hspace{1cm} % your specified distance
\begin{minipage}{4cm}
  \includegraphics[width=\textwidth]{yourimagename}
\end{minipage}

\mbox{}\hfill
\begin{minipage}[c]{4cm}
Faculty of science
Faculty of science
Faculty of science
Faculty of science
Faculty of science
\end{minipage}% 
\hspace{1cm} % your specified distance
\begin{minipage}{4cm}
  \includegraphics[width=\textwidth]{yourimagename}
\end{minipage}
\end{document}

Note the % at the end of the first minipages to avoid extra white space that would otherwise be inserted.

share|improve this answer
    
Thanks for your answer, just one thing: I’m new to Latex and I’ve never used the minipage environment before so this might be a stupid question, but in your code, how does Latex know where I would like the minipage to be? I mean, suppose now I place another logo in the bottom right hand corner of the page and I want to do the same, what happens then? –  Percy Aug 31 '12 at 12:35
    
@Percy LaTeX starts at the top of the current page. The \hfill command (horizontal fill) pushes it to the right. If you want to have another one at the bottom, you could use \vfill (vertical fill) –  cmhughes Aug 31 '12 at 15:13
add comment

Another option is to use coffinfs from the xcoffins package:

\documentclass{article}
\usepackage[margin=1cm,showframe=true]{geometry}
\usepackage[demo]{graphicx}% just for the example
\usepackage{xcoffins}
\usepackage{lipsum}% just to generate some text for the example

\newlength\logosz
\setlength\logosz{2.5cm}
\newlength\logosep
\setlength\logosep{1.25mm}

\begin{document}

% coffins allocation
\NewCoffin \Result
\NewCoffin \Institution
\NewCoffin \Logo

% fill the coffins
\SetHorizontalCoffin \Result{}
\SetVerticalCoffin \Institution{7cm} {\noindent\raggedleft Faculty of Science}
\SetVerticalCoffin \Logo{2.5cm} {\vspace*{\logosep}\noindent\includegraphics[width=\logosz,height=\logosz]{logo}}

% Join the coffins
\JoinCoffins \Result \Logo(\textwidth-\logosz-\logosep,10pt)
\JoinCoffins \Result[\Logo-vc,\Logo-l] \Institution [vc,r](-1cm,0pt)

% Typeset \Result
\noindent\TypesetCoffin \Result

\lipsum[1-4]

\end{document}

enter image description here

Adding more text to the \Institution coffin still preserves the vertical alignment and the 1cm separation from the \Logo coffin:

\documentclass{article}
\usepackage[margin=1cm,showframe=true]{geometry}
\usepackage[demo]{graphicx}
\usepackage{xcoffins}
\usepackage{lipsum}

\newlength\logosz
\setlength\logosz{2.5cm}
\newlength\logosep
\setlength\logosep{1.25mm}

\begin{document}

% coffins allocation
\NewCoffin \Result
\NewCoffin \Institution
\NewCoffin \Logo

% fill the coffins
\SetHorizontalCoffin \Result{}
\SetVerticalCoffin \Institution{7cm} {\noindent\raggedleft Faculty of Science Faculty of Science Faculty of Science Faculty of Science Faculty of Science Faculty of Science Faculty of Science}
\SetVerticalCoffin \Logo{2.5cm} {\vspace*{\logosep}\noindent\includegraphics[width=\logosz,height=\logosz]{logo}}

% Join the coffins
\JoinCoffins \Result \Logo(\textwidth-\logosz-\logosep,10pt)
\JoinCoffins \Result[\Logo-vc,\Logo-l] \Institution [vc,r](-1cm,0pt)

% Typeset \Result
\noindent\TypesetCoffin \Result

\lipsum[1-4]

\end{document}

enter image description here

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

share|improve this answer
add comment

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.