TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having a hard time positioning text. Especially if I need to 'float' elements to different sides. Currently, I'm trying to show a header with a 'subheader' that should be to the right of the header. Exactly to the right; not under it, not above it. Something like this:

MAIN TITLE                                 SUB TITLE

And here goes all the text, over the full page width. 
The sub title should be exactly where the content box
ends, no matter what the size of the main title, nor 
what the size of the sub title. 


This is another set of titles that shows just exactly
that the text subtitle should jump to the right of the
page, no matter the size.

I've tried many things but can not get this done. My closest fix was something like this:




\newcommand{\subtitle}[1]{\fbox{\vbox to 0pt{\hbox to 12.8cm{\hfill {#1}}}}}
\newcommand{\maintitle}[1]{\noindent\emph{#1 \vspace{0.01in}}}




\subtitle{And a longer subtitle}
\maintitle{A longer title}



And this is what it looks like:

enter image description here

My problems are the following:

  • In order to prevent that the position of the box is being influenced by the title, I need to actually put it before the title (so subtitle precedes title). This feels semantically wrong.
  • Whatever I do, I can not get it to align at the same line. Always, whatever I put first pushes the other text down, even though it is a little bit.
  • Creating a \hfill in an \hbox in an \vbox in an \fbox looks too complicated if I just want to float this box to the right. This should be easier, or not...?

What is the right way to tackle this issue?

share|improve this question
up vote 1 down vote accepted

To duplicate your ASCII art and add a box around it, the following works:

enter image description here

\usepackage{parskip}% http://ctan.org/pkg/parskip
\usepackage{blindtext}% http://ctan.org/pkg/blindtext
\newcommand{\mytitles}[2]{% \mytitles{<main>}{<sub>}



\mytitles{A longer title}{And a longer subtitle}



The above MWE provides \mytitles{<main>}{<sub>} for setting the <main> and <sub> titles. It creates a box of size \textwidth but corrects for the double \fboxsep and \fboxrule used to surround the titles (using \framebox rather than \makebox). Since the box has a specific width, \hfill "knows" how far to stretch, pushing either titles flush with the (box) margin.

I've introduced \uppercase, but this is not necessary. You can, of course, also change the font shape, as in your MWE:

\newcommand{\mytitles}[2]{% \mytitles{<main>}{<sub>}

It would also be possible to add more automated checks of title widths (to avoid overlap or encourage wrapping).

share|improve this answer
Great, thanks, works as a charm! In fact, I only put the borders to show how the boxes were being placed, but it was no problem disabling the boxes in your code. Also, I've been wondering for a while what MWE stands for...? (I understand it refers to the OP sample code, but what do the letters mean?) – user Feb 21 '12 at 12:58
@user1162541 -- MWE = "minimal working example". here's an explanation that will tell you more than you want to know. – barbara beeton Feb 21 '12 at 14:57
@barbarabeeton Thanks! – user Feb 22 '12 at 3:18

Your Answer


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.