Ambidextrous alignment in LaTeX
March 15, 2011 1:56 PM   Subscribe

LaTeX question: I want to left-align the beginning of a line, and right-align the end of the line—with a huge gap in the middle if necessary.

Possible complication: the left-aligned part is the bold heading of a \paragraph{}. I'm also indenting the text on following lines, but that should be irrelevant. Right now I have the following code:


\paragraph{First part goes here} End of line here \hangpara{1.5em}{1}\\
Indented text indented text indented text indented text indented text
Indented text indented text indented text indented text indented text...



And the result currently looks like this:


First part goes here End of line here
    Indented text indented text indented text indented text indented text
    Indented text indented text indented text indented text indented text...


I want the "End of line here" to be aligned with the right edge of the page, like this:


First part goes here                                                 End of line here
    Indented text indented text indented text indented text indented text
    Indented text indented text indented text indented text indented text...


Is there a way to do that? (By the way, I don't care about proper code style or re-usability, since I'm only using it in one document. I just want it to look right.)
posted by Chicken Boolean to Computers & Internet (11 answers total)
 
Put \hfill between the two parts of the line.
posted by Commander Rachek at 2:15 PM on March 15, 2011 [1 favorite]


Response by poster: That almost works—if the line is long enough that it gets close to the right edge already, \hfill creates a space and pushes last few words onto the next line. This can be prevented by replacing all the spaces in the rest of the line with non-breaking spaces (~s) but I hope there's a less ugly way.
posted by Chicken Boolean at 2:35 PM on March 15, 2011


A search term that might help is "dot leader" or "tab leader", which is what they are called in layout programs such as Indesign (for example a newspaper's staff box usually makes use of this).
posted by miscbuff at 3:02 PM on March 15, 2011


Best answer: Without using \paragraph the following works; could you possibly replace it with just \bf?

\begin{tabbing}
First part of line 1 \` last part of line 1\\
\end{tabbing}
posted by Dr. Eigenvariable at 3:48 PM on March 15, 2011


\begin{flushleft}really long to fill up the whole line\end{flushleft}\vspace{-3.4em}\begin{flushright}even more words over here this is longer than a line can be\end{flushright}

This is a really kludgy way that will make LaTeX cry.
posted by anaelith at 4:01 PM on March 15, 2011


I haven't got my TeX book here, but I'd say that Commander Rachek's proposal is half-correct. Wouldn't you also wan to indicate that the location after "End of line here" is a preferred place to break the line? ISTR that the way to do this is to assign a negative "penalty" to that position. Can't recall more than that, but google might lead you to the right place.

Or, you could search/ask here.
posted by lex mercatoria at 4:30 PM on March 15, 2011


Response by poster: Thanks everyone!

I tried anaelith's suggestion but the vertical alignment came out wrong with \vspace{-.34em} (maybe a font issue).

Dr. Eigenvariable's suggestion causes the \hangpara to be ignored if it's inside the "tabbing" environment, and results in strangely uneven indentation if I put it afterward with the \hangpara{1.5em}{0}. But it worked when I put the \hangpara{1.5em}{0} before the \begin{tabbing}—somehow it doesn't apply the indentation to the paragraph title line.
posted by Chicken Boolean at 5:54 PM on March 15, 2011


It was -3.4 (note decimal place) for me, but mostly just trial and error (yes, I know, BAD BAD BAD). Theoretically, you should be able to write the length needed in terms of settoheight, parsep, and so on... but I wasn't really having any luck with it.
posted by anaelith at 7:29 PM on March 15, 2011


I must be missing something, because I don't see why \hfil and \penalty won't work for you. I also remembered that \break should be defined as something like \penalty-10000, so you should be able to do

\noindent First part of line \hfil last part of line\break

posted by lex mercatoria at 11:33 PM on March 15, 2011


\noindent Left hand side\hfill Right hand side\\
\indent blah blah blah

works for me.
posted by pharm at 4:30 AM on March 16, 2011


or, with your \paragraph usage:

\paragraph{Left hand side}\hfill Right hand side\\
\indent blah blah blah...
posted by pharm at 4:33 AM on March 16, 2011


« Older The New Macbook Pro: Go for the SSD or the ATA?   |   Interval training is great, but what kind? Newer »
This thread is closed to new comments.