layoutlatexwidth

Latex: hfill to a certain width


I'm currently doing something like:

a\hfill{}b

which puts 'a' at the far left, and 'b' at the far right of the page. However, I'd like 'b' to be exactly half way. Is there a \hfill equivalent where I can say \hfill{0.5\textwidth}? I don't know the width of 'a'.

Obviously, I could use tabular, or maybe minipage, but the rest of the code here is pretty complicated, so I'd rather not mess with it.

Edit:

a and b are both subfloats (subfigure) with lstinputlistings in them.


Solution

  • \documentclass{article}
    
    \begin{document}
    \noindent\hbox to 0.5\textwidth{a}b
    
    Curabitur viverra ligula a dui condimentum tempus. Aenean convallis, massa ut fermentum
    convallis, leo justo iaculis lectus, quis molestie orci ligula ut leo. Quisque vitae neque   
    sit amet tortor convallis rhoncus ac at nibh. Cras sit amet mauris sit amet neque 
    tincidunt iaculis non non ante. Proin quis nisi porttitor enim adipiscing bibendum et  
    fermentum magna. Morbi sapien nibh, venenatis in fringilla id, laoreet ut libero. 
    \end{document}
    

    NB: this works if width of a is less than 0.5\textwidth so the multicol answer is probably more reasonable